toArray(); $this->addElement('text', 'title', array('label' => 'Title', 'required' => true)); $resize = $config['image']['width'] . 'x' . $config['image']['height'] . $config['image']['resizeMethodAlias']; $validators = array( array('IsImage', true), array( 'ImageSize', true, array( 'minwidth' => $config['image']['width'], 'minheight' => $config['image']['height'] ) ) ); $this->addElement( 'extendedImage', 'image', array( 'label' => 'Image', 'required' => true, 'resize' => $resize, 'validators' => $validators ) ); $this->addElement('textarea', 'description', array('label' => 'Description')); $description = $this->getElement('description'); $lengthValidator = new \Qs_Validate_StringLength(array( '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', array('label' => 'Show on user end', 'decoration' => 'simple')); return $this; } /** * @return AbstractForm */ protected function _initLinkDisplayGroup() { $groupElements = array(); $this->addElement( 'select', 'linkType', array( 'label' => 'Link Type', 'multioptions' => array('none' => 'No Link', 'url' => 'URL', 'cms' => 'Site Page') ) ); $groupElements[] = 'linkType'; $this->addElement( 'text', 'url', array('label' => 'URL', 'description' => 'Example: http://www.adaptainc.com') ); if ($this->_getData('linkType') == WideSlide\AbstractObj::LINK_TYPE_URL) { $this->getElement('url')->addValidator('url'); } $groupElements[] = 'url'; $this->addElement( 'select', 'pageId', array( 'label' => 'Site Page', 'escapeLabel' => false, 'multioptions' => array('' => '- Select Page -') + $this->_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')) && 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 = array($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 = array($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 = array( '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', array($options), 'wideSlideFrom'); return parent::render($view); } }