_dfRelations = $this->getConfigArray('dynamicFormRelations'); return parent::init(); } protected function _initElements() { $config = Qs_Application::getConfig('WideSlide')->toArray(); $this->addElement('text', 'title', ['label' => 'Title', 'required' => false]); $this->addElement('select','slideType', ['label' => 'Slide Type', 'multioptions' => [ AbstractObj::SLIDE_TYPE_IMAGE => 'Image', AbstractObj::SLIDE_TYPE_VIDEO => 'Video' ]]); $resize = $config['image']['width'] . 'x' . $config['image']['height'] . $config['image']['resizeMethodAlias']; $validators = [ ['IsImage', true], [ 'ImageSize', true, [ 'minwidth' => $config['image']['width'], 'minheight' => $config['image']['height'], ], ], ]; $this->addElement( 'extendedImage', 'image', [ 'label' => 'Image', 'resize' => $resize, 'validators' => $validators, ] ); $this->addElement('media', 'video', ['label' => 'Video']); $this->addDisplayGroup(['slideType', 'image', 'video'], 'slideTypeGroup', ['legend' => '']); if (($slideType = $this->_getData('slideType'))) { switch ($slideType) { case AbstractObj::SLIDE_TYPE_VIDEO: $this->getElement('video')->setRequired(); break; case AbstractObj::SLIDE_TYPE_IMAGE: $this->getElement('image')->setRequired(); break; } $this->_addAsterisk(['image', 'video']); } $this->addElement('textarea', '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', ['label' => 'Link Text']); $groupElements[] = 'linkText'; $this->addDisplayGroup($groupElements, 'linkTypeGroup', ['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(); break; } $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 = [$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; } }