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

RichtextareaWidget::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 16
rs 9.8666
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