Source of file InputSelect.php
Size: 2,451 Bytes - Last Modified: 2015-12-22T09:12:14-05:00
../src/View/Helper/InputSelect.php
123456789101112131415161718192021222324252627282930313233343536
Covered by 1 test(s):
37
Covered by 1 test(s):
3839
Covered by 1 test(s):
40
Covered by 1 test(s):
4142
Covered by 1 test(s):
4344
Covered by 1 test(s):
45
Covered by 1 test(s):
46
Covered by 1 test(s):
47
Covered by 1 test(s):
48
Covered by 1 test(s):
49
Covered by 1 test(s):
5051525354555657585960
Covered by 3 test(s):
616263
Covered by 3 test(s):
64
Covered by 1 test(s):
65
Covered by 1 test(s):
66
Covered by 1 test(s):
67
Covered by 1 test(s):
68
Covered by 1 test(s):
69
Covered by 3 test(s):
707172
Covered by 3 test(s):
7374757677787980818283848586
Covered by 1 test(s):
8788
Covered by 1 test(s):
89
Covered by 1 test(s):
9091
Covered by 1 test(s):
929394
| <?php /** * Select Input View Helper * * @category PHP * @package MvcLite * @subpackage View\Helper * @since File available since release 1.1.x * @author Cory Collier <corycollier@corycollier.com> */ namespace MvcLite\View\Helper; use MvcLite\View\Helper\InputElementAbstract as InputElementAbstract; /** * Select Input View Helper class * * @category PHP * @package MvcLite * @subpackage View\Helper * @since Class available since release 1.1.x * @author Cory Collier <corycollier@corycollier.com> */ class InputSelect extends InputElementAbstract { /** * Method to render a select element * * @param array $options * @param array $attribs * @return string */ public function render($name, $attribs = []) { $options = $attribs['options']; unset($attribs['options']); $defaults = $this->getDefaultAttribs($name, 'select'); $attribs = array_merge($defaults, $attribs); $template = '<label for="!id">!label</label>' . '<select!attribs>!options</select>'; return strtr($template, [ '!id' => $attribs['id'], '!label' => $attribs['label'], '!attribs' => $this->getHtmlAttribs($attribs), '!options' => $this->buildOptions($options), ]); } /** * method to take an array and turn it into a string of li elements * * @param array $options * @return string */ protected function buildOptions($options = []) { $template = '<option value="!value">!label</option>'; // iterate through the options, turning them into strings foreach ($options as $value => $label) { unset($options[$value]); $options[$label] = strtr($template, [ '!value' => $value, '!label' => $label, ]); } // return the array imploded into a string by newline characters return implode(PHP_EOL, $options); } /** * Local override of the isValidAttribute method. * * @param string $name The name of the attribute. * * @return boolean True if valid, false if not. */ protected function isValidAttribute($name) { $no = [ 'label' ]; if (in_array($name, $no)) { return false; } return true; } } |