_dfRelations = $this->_prepareDynamicFormRelationsElements($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 _initElements() { $config = Qs_Application::getConfig('WideSlide')->toArray(); $this->addElement('text', 'title', ['label' => 'Title', 'required' => true]); $resize = $config['image']['width'] . 'x' . $config['image']['height'] . $config['image']['resizeMethodAlias']; $resize2 = $config['image2']['width'] . 'x' . $config['image2']['height'] . $config['image2']['resizeMethodAlias']; $validators = [ ['IsImage', true], [ 'ImageSize', true, [ 'minwidth' => $config['image']['width'], 'minheight' => $config['image']['height'] ] ] ]; $validators2 = [ ['IsImage', true], [ 'ImageSize', true, [ 'minwidth' => $config['image2']['width'], 'minheight' => $config['image2']['height'] ] ] ]; $this->addElement( 'extendedImage', 'image', [ 'label' => 'Background Image', 'required' => true, 'resize' => $resize, 'validators' => $validators ] ); $this->addElement( 'extendedImage', 'image2', [ 'label' => 'Slide Image', 'required' => true, 'resize' => $resize2, 'validators' => $validators2 ] ); $this->addElement('htmlEditor', 'description', ['label' => 'Description']); // $description = $this->getElement('description'); // $lengthValidator = new Qs_Validate_StringLength([ // 'max' => $config['descriptionMaxLength'], // 'elementLabel' => $description->getLabel() // ]); // $description->addValidator($lengthValidator, true); // $description->setDescription('Text space is limited to ' . $config['descriptionMaxLength'] . ' characters.'); $this->_initLinkDisplayGroup(); $this->addElement('checkbox', 'enabled', ['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'] + (new Qs_Db_Table('WideSlideLinkType'))->get4Select() ] ); $groupElements[] = 'linkType'; $this->addElement('url', 'url', ['label' => 'URL']); $groupElements[] = 'url'; if ($this->_getData('linkType') !== AbstractObj::LINK_TYPE_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 AbstractObj::LINK_TYPE_URL: $this->getElement('url')->setRequired(); break; case AbstractObj::LINK_TYPE_CMS: $this->getElement('pageId')->setRequired(); } $this->getElement('linkText')->setRequired(); } $groupElements = Qs_Array::excludeValue($groupElements, 'linkType'); $this->_addAsterisk($groupElements); return $this; } /** * @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; } public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); self::dfClearUnusedValues($values); return $values; } }