/** * Sets the element option. * * @param string $value Element value. * @param bool $escape Try to escape html in value. * * @return $this */ public function setValue($value, $escape = false) { parent::setValue($value == '' ? $this->getOption('defaultValue') : $value, $escape); if ($this->_value == $this->getAttribute('value')) { $this->setOption('checked', 'checked'); } else { $this->setOption('checked', null); } return $this; }
/** * Get allowed options for this element. * * @return array */ public function getAllowedOptions() { return array_merge(parent::getAllowedOptions(), ['elementOptions', 'disabledOptions', 'using', 'hasEmptyValue']); }
/** * Get element default attribute. * * @return array */ public function getDefaultAttributes() { return array_merge(parent::getDefaultAttributes(), ['type' => $this->getInputType()]); }
/** * Get element default attribute. * * @return array */ public function getDefaultAttributes() { return array_merge(parent::getDefaultAttributes(), ['class' => '']); }
/** * Get allowed options for this element. * * @return array */ public function getAllowedOptions() { return array_merge(parent::getAllowedOptions(), ['buttonTitle']); }
/** * Validate entity model. * * @param array &$data Data to validate. * @param AbstractElement $element Element object. * * @return bool */ protected function _validateElement(&$data, $element) { $isValid = true; if ($element->isIgnored()) { return $isValid; } // Filter data. if (!empty($this->_filters[$element->getName()])) { foreach ($this->_filters[$element->getName()] as $filter) { $data[$element->getName()] = $this->getDI()->get('filter')->sanitize($data[$element->getName()], $filter); } } // Check field requirement. if ($element->getOption('required')) { if (!isset($data[$element->getName()])) { $isValid = false; $this->addError(sprintf($this->_(self::MESSAGE_FIELD_IS_REQUIRED), $this->_($element->getOption('label'))), $element->getName()); } // Check that field can not be empty. if (!$element->getOption('emptyAllowed') && empty($data[$element->getName()])) { $isValid = false; $this->addError(sprintf($this->_(self::MESSAGE_FIELD_IS_EMPTY), $this->_($element->getOption('label'))), $element->getName()); } } /** * What data must have element, that was not sent to server? If used null as default - all will be null. */ if ($this->_useDefaultValue) { if (!isset($data[$element->getName()]) || $data[$element->getName()] == '') { $data[$element->getName()] = $element->getOption('defaultValue'); } } return $isValid; }
/** * Get element default attribute. * * @return array */ public function getDefaultAttributes() { return array_merge(parent::getDefaultAttributes(), ['class' => 'form_element_heading']); }
/** * Render element. * * @return string */ public function render() { $href = $this->getValue(); if ($href) { $href = $this->getDI()->get('url')->get($href); } else { $href = 'javascript:;'; } $this->setAttribute('href', $href); return parent::render(); }
/** * Get element default attribute. * * @return array */ public function getDefaultAttributes() { return array_merge(parent::getDefaultAttributes(), $this->getOption('isSubmit') ? ['type' => 'submit', 'class' => 'btn btn-primary'] : ['class' => 'btn']); }
/** * Add element to form. * * @param AbstractElement $element Element object. * @param int|null $order Element order. * * @return $this */ public function add(AbstractElement $element, $order = null) { if (!$order) { $order = $this->_currentOrder++; } $element->setContainer($this); $this->_elements[$order] = $element; $this->_order[$element->getName()] = $order; if ($this->getIdentity() !== null) { $element->setAttribute('name', sprintf('%s[%s]', $this->getIdentity(), $element->getName())); } return $this; }
/** * Render element. * * @return string */ public function render() { if (!$this->getAttribute('value') && $this->getValue()) { $this->setAttribute('value', $this->getValue()); } return parent::render(); }
/** * Get element default attribute. * * @return array */ public function getDefaultAttributes() { return array_merge(parent::getDefaultAttributes(), ['class' => 'btn form_link_button']); }