setDfRelations($this->getConfigArray('dynamicFormRelations')); return parent::init(); } protected function _prepareDynamicFormRelationsElements($config) { $languageList = array_keys(Qs_Db_Language::getList()); $rules = $config[0]['rules']; foreach ($rules as $key => $rule) { foreach($rule['_elements'] as $element) { foreach ($languageList as $language) { $config[0]['rules'][$key]['_elements'][] = $element . '_' . $language; } } } return $config; } protected function _getSlideConfig() { return \Qs_Application::getConfig('WideSlide')->toArray(); } protected function _initElements() { $config = $this->_getSlideConfig(); $this->addElement('text', 'title', array('label' => 'Title', 'required' => true)); $resize = $config['image']['width'] . 'x' . $config['image']['height'] . $config['image']['resizeMethodAlias']; $validators = array( array('IsImage', true), array( 'ImageSize', true, array( 'minwidth' => $config['image']['width'], 'minheight' => $config['image']['height'] ) ) ); $this->addElement( 'extendedImage', 'image', array( 'label' => 'Image', 'required' => true, 'resize' => $resize, 'validators' => $validators ) ); $this->addElement('htmlEditor', 'description', array('label' => 'Description')); $description = $this->getElement('description'); $lengthValidator = new \Qs_Validate_StringLength(array( 'max' => $config['descriptionMaxLength'], 'elementLabel' => $description->getLabel() )); $description->addValidator($lengthValidator, true); $description->setDescription('Text space is limited to ' . $config['descriptionMaxLength'] . ' characters.'); $this->addElement( 'select', 'descriptionPosition', [ 'label' => 'Description Position', 'multioptions' => ['left' => 'Left', 'center' => 'Center', 'right' => 'Right'] ] ); $this->_initLinkDisplayGroup(); $this->addElement('checkbox', 'enabled', array('label' => 'Show on user end', 'decoration' => 'simple')); return $this; } /** * @return AbstractForm */ protected function _initLinkDisplayGroup() { $groupElements = []; $this->addElement( 'select', 'linkType', [ 'label' => 'Link Type', 'multioptions' => ['' => 'No Link', 'url' => 'URL', 'cms' => 'Site Page'] ] ); $groupElements[] = 'linkType'; $this->addElement('url', 'url', ['label' => 'URL']); $groupElements[] = 'url'; if ($this->_getData('linkType') !== 'url') { $this->getElement('url')->removeValidator('url'); } $this->addElement( 'select', 'pageId', [ 'label' => 'Site Page', 'escapeLabel' => false, 'multioptions' => ['' => 'Select One'] + App_Cms_Obj::getInstance()->getPages4Select() ] ); $groupElements[] = 'pageId'; $this->addElement('text', 'linkText', array('label' => 'Link Text')); $groupElements[] = 'linkText'; $this->addDisplayGroup($groupElements, 'linkTypeGroup', array('legend' => 'Link')); if (($linkType = $this->_getData('linkType'))) { switch ($linkType) { case 'url': $this->getElement('url')->setRequired(); break; case 'cms': $this->getElement('pageId')->setRequired(); break; } $this->getElement('linkText')->setRequired(); } $groupElements = Qs_Array::excludeValue($groupElements, 'linkType'); $this->_addAsterisk($groupElements); $this->_addHiddenClass($groupElements); return $this; } /** * @return array|bool */ protected function _getPages4Select() { $cmsObj = \App_Cms_Obj::getInstance(); return $cmsObj->getPages4Select(); } /** * @param array|string $elementsNames * @return AbstractForm */ protected function _addAsterisk($elementsNames) { if (!is_array($elementsNames)) { $elementsNames = array($elementsNames); } foreach ($elementsNames as $elementName) { $element = $this->getElement($elementName); if (!$element->isRequired()) { $element->getDecorator('Label')->setOption('class', 'required'); } } return $this; } /** * @param array|string $elementsNames * @return AbstractForm */ protected function _addHiddenClass($elementsNames) { if (!is_array($elementsNames)) { $elementsNames = array($elementsNames); } foreach ($elementsNames as $elementName) { $element = $this->getElement($elementName); /** @var \Qs_Form_Decorator_Label $label */ $label = $element->getDecorator('Label'); $label->setTagOption('class', 'hidden'); /** @var \Qs_Form_Decorator_HtmlTag $htmlTag */ $htmlTag = $element->getDecorator('HtmlTag'); $htmlTag->setOption('class', 'hidden'); } return $this; } // public function render(\Zend_View_Interface $view = null) // { // /** @var \Qs_Doc $doc */ // $doc = \Zend_Registry::get('doc'); // // $doc->addScript('js/app/wideSlide/admin/form.js'); // // $options = array( // 'form' => $this->getId(), // 'linkType' => $this->getElement('linkType')->getId(), // 'url' => $this->getElement('url')->getId(), // 'pageId' => $this->getElement('pageId')->getId(), // 'linkText' => $this->getElement('linkText')->getId(), // ); // $doc->addInitObject('App_WideSlide_Admin_Form', array($options), 'wideSlideFrom'); // // return parent::render($view); // } }