_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->_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', 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(); 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 = 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; } }