_dfRelations = $this->getConfigArray('dynamicFormRelations'); return parent::init(); } 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']; $validators = [ ['IsImage', true], [ 'ImageSize', true, [ 'minwidth' => $config['image']['width'], 'minheight' => $config['image']['height'], ], ], ]; $this->addElement( 'extendedImage', 'image', [ 'label' => 'Image', 'required' => true, 'resize' => $resize, 'validators' => $validators, ] ); $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'; $events = (new Qs_Db_Table('Event'))->get4Select( ['id', 'title'], ['`startDate` > "' . date('Y-m-d') . '"', '`enabled` = "y"'], 'startDate' ); $this->addElement('select', 'eventId', ['label' => 'Event', 'multioptions' => ['' => 'Select One'] + $events]); $groupElements[] = 'eventId'; $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; case AbstractObj::LINK_TYPE_EVENT: $this->getElement('eventId')->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 = [$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; } }