123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace Cube\Form\Element;
- use Cube\Form\Element;
- class Radio extends Element
- {
-
- protected $_element = 'radio';
-
- public function __construct($name)
- {
- parent::__construct($this->_element, $name);
- }
-
- public function render()
- {
- $output = null;
- $value = $this->getValue();
- $translate = $this->getTranslate();
- foreach ((array)$this->_multiOptions as $key => $option) {
- $checked = ($value == $key) ? 'checked="checked" ' : '';
- if (is_array($option)) {
- $title = isset($option[0]) ? $option[0] : null;
- $description = isset($option[1]) ? $option[1] : null;
- if (isset($option[2])) {
- $this->addMultiOptionAttributes($key, $option[2]);
- }
- }
- else {
- $title = $option;
- $description = null;
- }
- $attributes = array(
- 'type="' . $this->_element . '"',
- 'name="' . $this->_name . '"',
- 'value="' . $key . '"',
- $this->renderAttributes(),
- $this->renderOptionAttributes($key),
- $checked
- );
- $output .= '<label class="radio">'
- . '<input ' . implode(' ', array_filter($attributes)) . '>'
- . ' ' . $translate->_($title)
- . (($description !== null) ? '<span class="help-block">' . $translate->_($description) . '</span>' : '')
- . '</label>'
- . "\n";
- }
- return $output;
- }
- }
|