addPrefixPath( 'App\\Company\\Admin\\Form\\Decorator', 'App/Company/Admin/Form/Decorator/', self::DECORATOR ); return $this; } public function setLabel($label) { $this->_label = $label; return $this; } public function getLabel() { return $this->_label; } public function isRequired() { return $this->_isRequired; } public function setRequired($value) { $this->_isRequired = (bool) $value; return $this; } public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return $this; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('FormElements'); $this->addDecorator(['tbody' => 'HtmlTag'], ['tag' => 'tbody']); $this->addDecorator('PositionTFoot'); $this->addDecorator('PositionTHead'); $this->addDecorator(['table' => 'HtmlTag'], ['tag' => 'table', 'class' => 'table table-striped']); $this->addDecorator(['dd' => 'HtmlTag'], ['tag' => 'dd']); $this->addDecorator('Label', ['tag' => 'dt']); } return $this; } public function initRender() { if (!$this->loadDefaultDecoratorsIsDisabled()) { $id = $this->getId(); $this->getDecorator('dd')->setOption('id', $id . '-element'); $this->getDecorator('table')->setOption('id', $id . '-table'); if (!$this->getLabel()) { /** @var \Qs_Form_Decorator_Label $label */ $label = $this->getDecorator('Label'); $label->setTagOption('class', 'hidden'); } } return parent::initRender(); } protected function _addResources() { $doc = $this->getDoc(); $doc->addScript('js/app/company/admin/positionSubForm.js'); $renderUrl = Qs_SiteMap::findFirst(null, ['type' => 'Company\\Admin\\'], null, 'url'); $scriptOptions = [ 'formId' => $this->_parentForm->getId(), 'subFormId' => $this->getFullId(), 'renderUrl' => $renderUrl, 'renderParams' => $this->_parentForm->getPrimaryKey(), ]; $doc->addInitObject('app.company.admin.PositionSubForm', [$scriptOptions], $this->getName()); return parent::_addResources(); } public function addSubForm(Zend_Form $form, $name, $order = null) { /** @var \Zend_Form_Element $element */ foreach ($form as $element) { if (!($element instanceof Zend_Form_Element_Hidden) && !($element instanceof PositionItemOptions)) { if ($this->isRequired()) { $element->setRequired(); } } } return parent::addSubForm($form, $name, $order); } public function getMessages($name = null, $suppressArrayNotation = false) { if (null !== $name) { if (isset($this->_elements[$name])) { return $this->getElement($name)->getMessages(); } else if (isset($this->_subForms[$name])) { return $this->getSubForm($name)->getMessages(null, true); } /** @var Qs_Form_SubForm $subForm */ foreach ($this->getSubForms() as $subForm) { if ($subForm->isArray()) { $belongTo = $subForm->getElementsBelongTo(); if ($name == $this->_getArrayName($belongTo)) { return $subForm->getMessages(null, true); } } } } $customMessages = $this->_getErrorMessages(); $messages = []; /** @var \Zend_Form_Element $element */ foreach ($this->getElements() as $name => $element) { $eMessages = $element->getMessages(); if (!empty($eMessages)) { $messages[$name] = $eMessages; } } foreach ($this->getSubForms() as $key => $subForm) { $merge = $subForm->getMessages(null, true); if (!empty($merge)) { if (!$subForm->isArray()) { $merge = [$key => $merge]; } else { $merge = $this->_attachToArray($merge, $subForm->getElementsBelongTo()); } $messages = $this->_array_replace_recursive($messages, $merge); } } if (!$suppressArrayNotation && $this->isArray() && !$this->_getIsRendered()) { $messages = $this->_attachToArray($messages, $this->getElementsBelongTo()); } return Qs_Array::mergeAssoc($messages, $customMessages); } public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); foreach ($values as $index => $value) { if (empty($value['positionId']) && empty($value['userId'])) { unset($values[$index]); } } return $values; } }