_blockOptions) { $this->_blockOptions = [ '' => '-', self::TYPE_DEFAULT => 'Full Sitemap', self::TYPE_SUBPAGES => 'Subpages List', ]; } return (false !== $key) ? Qs_Array::get($this->_blockOptions, $key) : $this->_blockOptions; } protected function _getPages4Select() { if (null === $this->_pageOptions) { $this->_pageOptions = ['' => '-']; $dataObj = new App_Cms_Obj(); $filters = ['`Page`.`system` != "y"', '`Page`.`enabled` = "y"']; $this->_pageOptions += $dataObj->getPages4Select(0, $filters); } return $this->_pageOptions; } protected function _initElements() { $this->addElement( 'select', 'type', ['label' => 'Block Type', 'required' => true, 'multiOptions' => $this->_getBlockType4Select()] ); $this->addElement( 'select', 'pageId', [ 'label' => 'Select Page', 'description' => 'Required for "' . $this->_getBlockType4Select(self::TYPE_SUBPAGES) . '" type', 'multiOptions' => $this->_getPages4Select(), 'escapeLabel' => false, 'allowEmpty' => false, // необхідний що б спрацював валідатор Callback ] ); /** @var Zend_Form_Element_Select $pageId */ $pageId = $this->getElement('pageId'); $pageId->addValidator('Callback', true, [[$this, 'validatePageId']]); $pageId->getValidator('Callback')->setMessage( 'Page required and should have subpages', Zend_Validate_Callback::INVALID_VALUE ); return $this; } public function validatePageId($value, $context) { $isValid = true; if (self::TYPE_SUBPAGES == $context['type']) { if ('' == $value) { $isValid = false; } else { $hasChildren = (bool) Qs_SiteMap::findFirst( ['idParent' => $value, 'enabled' => 'y', 'system' => 'n'], null, null, 'id' ); if (!$hasChildren) { $isValid = false; } } } return $isValid; } }