/** * {@inheritDoc} */ public function render(ElementInterface $element) { if (!$element instanceof LoginFieldElement) { return ''; } $fields = $element->getFields(); if (1 == count($fields)) { $element->setAttribute('placeholder', current($fields)); return parent::render($element); } $template = $element->getOption('template') ?: '<div class="input-group">%s</div>'; $pattern = <<<EOT <input name="%s[0]" %s%s <span class="input-group-addon"> <select class="pull-right" name="%s[1]"> %s </select> </span> EOT; $name = $element->getName(); list($value, $field) = $element->getValue(); $attributes = array_replace($element->getAttributes(), array('type' => 'text', 'value' => $value)); if (!isset($attributes['class'])) { $attributes['class'] = 'form-control'; } $attribString = $this->createAttributesString($attributes); $patternField = '<option value="%s"%s>%s</option>' . PHP_EOL; $fieldString = ''; foreach ($fields as $key => $label) { $class = $field == $key ? ' selected' : ''; $fieldString .= sprintf($patternField, $key, $class, $label); } $html = sprintf($template, sprintf($pattern, $name, $attribString, $this->getInlineClosingBracket(), $name, $fieldString)); return $html; }
/** * Render a form <input> element from the provided $element * * @param ElementInterface $element * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { $src = $element->getAttribute('src'); if (empty($src)) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned src; none discovered', __METHOD__)); } return parent::render($element); }
/** * Render a form <input> element from the provided $element * * @param ElementInterface $element * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { $class = $element->getAttribute('class'); if (in_array($this->getType($element), array('submit', 'reset', 'button'))) { $class = 'btn' . (empty($class) ? '' : ' ' . $class); } $element->setAttribute('class', $class); return parent::render($element); }