Htmlarea::getDefaults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 2
rs 9.9332
c 0
b 0
f 0
1
<?php namespace Rocket\UI\Forms\Fields;
2
3
/**
4
 * Creates an HTMLArea with Form_element
5
 *
6
 * @method $this htmlarea(array $config)
7
 */
8
class Htmlarea extends Textarea
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    protected function getDefaults()
14
    {
15
        return parent::getDefaults() + [
16
            'htmlarea' => [
17
                'style' => 'advanced',
18
                'images' => true,
19
                'css' => true,
20
            ],
21
        ];
22
    }
23
24
    /**
25
     * Renders the scripts used for the htmlarea
26
     */
27
    protected function renderScript()
28
    {
29
        $controls = [
30
            'simple' => [
31
                'orderedlist',
32
                'unorderedlist',
33
                '|',
34
                'leftalign',
35
                'blockjustify',
36
                '|',
37
                'unformat',
38
                '|',
39
                'undo',
40
                'redo',
41
                'n',
42
                'bold',
43
                'italic',
44
                'underline',
45
                '|',
46
                'link',
47
                'unlink',
48
                '|',
49
                'cut',
50
                'copy',
51
                'paste',
52
            ],
53
            'advanced' => [
54
                'subscript',
55
                'superscript',
56
                '|',
57
                'orderedlist',
58
                'unorderedlist',
59
                '|',
60
                'outdent',
61
                'indent',
62
                '|',
63
                'leftalign',
64
                'centeralign',
65
                'rightalign',
66
                'blockjustify',
67
                '|',
68
                'unformat',
69
                '|',
70
                'undo',
71
                'redo',
72
                'n',
73
                'bold',
74
                'italic',
75
                'underline',
76
                'strikethrough',
77
                '|',
78
                'size',
79
                'style',
80
                '|',
81
                (($this->params['htmlarea']['images']) ? 'image' : ''),
82
                'hr',
83
                'link',
84
                'unlink',
85
                '|',
86
                'cut',
87
                'copy',
88
                'paste',
89
            ],
90
        ];
91
92
        $config = [
93
            'id' => $this->id,
94
            'controls' => $controls[$this->params['htmlarea']['style']],
95
            'footer' => false,
96
            'fonts' => ['Verdana', 'Arial', 'Georgia', 'Trebuchet MS'],
97
            'xhtml' => true,
98
            'images' => (bool) $this->params['htmlarea']['images'],
99
            'bodyid' => 'editor',
100
        ];
101
102
        if ($this->params['htmlarea']['css']) {
103
            $config['cssfile'] = \URL::to('css/minimal.css');
104
        }
105
106
        $registered_id = 'edit_form_elm_' . $this->id;
107
108
        $this->getJS()->ready(
109
            '$(document).one("after_content", function() {' .
110
            '   new TINY.editor.edit(\'' . $registered_id . '\',' . json_encode_with_functions($config) . '); ' .
111
            '   $(\'#' . $this->id . '\').closest("form").submit(function() {' . $registered_id . '.post(); });
112
            });'
113
        );
114
    }
115
116
    /**
117
     * Render the file as a textarea and not input
118
     */
119
    protected function renderInner()
120
    {
121
        $val = $this->input_attributes['value'];
122
        unset($this->input_attributes['value']);
123
124
        $attributes = $this->renderAttributes($this->input_attributes);
125
126
        $this->result .= "<textarea $attributes>$val</textarea>";
127
    }
128
}
129