Source of file InputCheckbox.php

Size: 1,709 Bytes - Last Modified: 2015-12-22T09:42:40-05:00

../src/View/Helper/InputCheckbox.php

1234567891011121314151617181920212223242526272829303132333435
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
36
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
373839
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
4041
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
42
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
43
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
44
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
45
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
46
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
4748495051525354555657585960
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
6162
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
63
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
6465
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
666768
<?php
/**
 * Checkbox Input View Helper
 *
 * @category    MvcLite
 * @package     Lib
 * @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;

/**
 * Checkbox Input View Helper class
 *
 * @category    MvcLite
 * @package     Lib
 * @subpackage  View_Helper
 * @since       Class available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class InputCheckbox extends InputElementAbstract
{
    /**
     * method to render a input[type=password] element
     *
     * @param array $attribs
     * @return string
     */
    public function render($name, $attribs = [])
    {
        $defaults = $this->getDefaultAttribs($name, 'checkbox');
        $attribs  = array_merge($defaults, $attribs);
        $template = '<div class="checkbox !classes">'
            . '<label><input!attribs>!label</label>'
            . '</div>';

        return strtr($template, [
            '!id'       => $attribs['id'],
            '!label'    => $attribs['label'],
            '!classes'  => $this->getAdditionalClasses($attribs),
            '!attribs'  => $this->getHtmlAttribs($attribs),
        ]);
    }

    /**
     * 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;
    }
}