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' => ['none' => 'No Link', 'url' => 'URL', 'cms' => 'Site Page'], ] ); $groupElements[] = 'linkType'; $this->addElement( 'text', 'url', ['label' => 'URL', 'description' => 'Example: ' . constant('EXAMPLE_URL')] ); if ($this->_getData('linkType') == WideSlide\AbstractObj::LINK_TYPE_URL) { $this->getElement('url')->addValidator('url'); } $groupElements[] = 'url'; $this->addElement( 'select', 'pageId', [ 'label' => 'Site Page', 'escapeLabel' => false, 'multioptions' => ['' => '- Select Page -'] + $this->_getPages4Select(), ] ); $groupElements[] = 'pageId'; $this->addElement('text', 'linkText', ['label' => 'Link Text']); $groupElements[] = 'linkText'; $this->addDisplayGroup($groupElements, 'linkTypeGroup', ['legend' => 'Link']); if (($linkType = $this->_getData('linkType')) && WideSlide\AbstractObj::LINK_TYPE_NONE != $linkType) { if (WideSlide\AbstractObj::LINK_TYPE_URL == $linkType) { $this->getElement('url')->setRequired(); } else { $this->getElement('pageId')->setRequired(); } $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 = [$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 = [$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 = [ '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', [$options], 'wideSlideFrom'); return parent::render($view); } }