123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- /**
- *
- * Cube Framework $Id$ CukK5Jfbrfv+Ux6Er/1HkfFj6DvYlJ23gmD8eg9Dtzw=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2017 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.10 [rev.1.10.01]
- */
- /**
- * radio buttons form element generator class
- */
- namespace Cube\Form\Element;
- use Cube\Form\Element;
- class Radio extends Element
- {
- /**
- *
- * type of element - override the variable from the parent class
- *
- * @var string
- */
- protected $_element = 'radio';
- /**
- *
- * class constructor
- *
- * @param string $name
- */
- public function __construct($name)
- {
- parent::__construct($this->_element, $name);
- }
- /**
- *
- * render the form element
- *
- * @return string
- */
- 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;
- }
- }
|