Completed
Push — master ( 78db53...7d214b )
by Cheren
02:18
created

BasicWidget   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 42
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 22 1
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Core
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Core".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\View\Widget;
17
18
use Cake\View\Form\ContextInterface;
19
use Cake\View\Widget\BasicWidget as BaseBasicWidget;
20
21
/**
22
 * Class BasicWidget
23
 *
24
 * @package Core\View\Widget
25
 */
26
class BasicWidget extends BaseBasicWidget
27
{
28
29
30
    /**
31
     * Render a text widget or other simple widget like email/tel/number.
32
     *
33
     * This method accepts a number of keys:
34
     *
35
     * - `name` The name attribute.
36
     * - `val` The value attribute.
37
     * - `escape` Set to false to disable escaping on all attributes.
38
     *
39
     * Any other keys provided in $data will be converted into HTML attributes.
40
     *
41
     * @param   array $data The data to build an input with.
42
     * @param   \Cake\View\Form\ContextInterface $context The current form context.
43
     * @return  string
44
     */
45
    public function render(array $data, ContextInterface $context)
46
    {
47
        $data += [
48
            'name'          => '',
49
            'val'           => null,
50
            'type'          => 'text',
51
            'escape'        => true,
52
            'templateVars'  => []
53
        ];
54
        $data['value'] = $data['val'];
55
        unset($data['val']);
56
57
        return $this->_templates->format('input', [
58
            'name'          => $data['name'],
59
            'type'          => $data['type'],
60
            'templateVars'  => $data['templateVars'],
61
            'attrs'         => $this->_templates->formatAttributes(
62
                $data,
63
                ['name', 'type', 'before', 'after']
64
            ),
65
        ]);
66
    }
67
}
68