Passed
Pull Request — master (#519)
by Paolo
04:19
created

RichtextareaWidget   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 16 1
1
<?php
2
namespace App\View\Widget;
3
4
use Cake\View\Form\ContextInterface;
5
use Cake\View\Widget\BasicWidget;
6
7
/**
8
 */
9
class RichtextareaWidget extends BasicWidget
10
{
11
    /**
12
     * Render a text area form widget.
13
     *
14
     * Data supports the following keys:
15
     *
16
     * - `name` - Set the input name.
17
     * - `val` - A string of the option to mark as selected.
18
     * - `escape` - Set to false to disable HTML escaping.
19
     *
20
     * All other keys will be converted into HTML attributes.
21
     *
22
     * @param array $data The data to build a textarea with.
23
     * @param \Cake\View\Form\ContextInterface $context The current form context.
24
     * @return string HTML elements.
25
     */
26
    public function render(array $data, ContextInterface $context)
27
    {
28
        $data += [
29
            'val' => '',
30
            'name' => '',
31
            'escape' => true,
32
            'templateVars' => [],
33
        ];
34
35
        return $this->_templates->format('richtext', [
36
            'name' => $data['name'],
37
            'value' => $data['val'],
38
            'templateVars' => $data['templateVars'],
39
            'attrs' => $this->_templates->formatAttributes(
40
                $data,
41
                ['name', 'val']
42
            ),
43
        ]);
44
    }
45
}
46