public function render(ElementInterface $element) { if ($element->getOption('static')) { return $this->getView()->formElementStatic($element); } return parent::render($element); }
/** {@inheritdoc} */ public function renderOptions(array $options, array $selectedOptions = array()) { $translatorEnabled = $this->isTranslatorEnabled(); $this->setTranslatorEnabled(false); $output = parent::renderOptions($options, $selectedOptions); $this->setTranslatorEnabled($translatorEnabled); return $output; }
public function renderOptions(array $options, array $selectedOptions = []) { $html = parent::renderOptions($options, $selectedOptions); foreach ($selectedOptions as $value => $label) { $html .= sprintf('<option value="%s" selected>%s</option>', $value, $label); } return $html; }
public function render(ElementInterface $element) { if ($element->hasAttribute('data-placeholder')) { $placeholder = $element->getAttribute('data-placeholder'); $placeholder = $this->getTranslator()->translate($placeholder, $this->getTranslatorTextDomain()); $element->setAttribute('data-placeholder', $placeholder); } return parent::render($element); }
/** * Render a form <select> element from the provided $element * @param ElementInterface $element * @param null|string $formType * @param array $displayOptions * @return string */ public function render(ElementInterface $element, $formType = null, array $displayOptions = array()) { if (array_key_exists('class', $displayOptions)) { $class = $element->getAttribute('class'); $class = $this->genUtil->addWords($displayOptions['class'], $class); $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper(); $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper); $element->setAttribute('class', $class); } if (array_key_exists('size', $displayOptions)) { $element->setAttribute('size', (int) $displayOptions['size']); } $this->formUtil->addIdAttributeIfMissing($element); $html = parent::render($element); return $html; }
/** * Select * * @param ElementInterface|null $element * @return string|Helper\FormSelect */ public function select(ElementInterface $element = null) { $helper = new Helper\FormSelect(); return $helper->__invoke($element); }
/** * Ensure that the value is set appropriately * * If the element's value attribute is an array, but there is no multiple * attribute, or that attribute does not evaluate to true, then we have * a domain issue -- you cannot have multiple options selected unless the * multiple attribute is present and enabled. * * @param mixed $value * @param array $attributes * @return array */ protected function validateMultiValue($value, array $attributes) { if (is_array($value) && (!isset($attributes['multiple']) || !$attributes['multiple'])) { return array(); } return parent::validateMultiValue($value, $attributes); }