Completed
Pull Request — master (#588)
by
unknown
14:32
created

SelectEditor::defaultRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
ccs 9
cts 9
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Form;
13
14
/**
15
 * SelectEditor
16
 *
17
 * @category  Xoops\Form\SelectEditor
18
 * @package   Xoops\Form
19
 * @author    Taiwen Jiang <[email protected]>
20
 * @copyright 2001-2015 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @link      http://xoops.org
23
 */
24
class SelectEditor extends ElementTray
25
{
26
    /**
27
     * @var array
28
     */
29
    public $allowed_editors = array();
30
31
    /**
32
     * @var Form
33
     */
34
    public $form;
35
36
    /**
37
     * @var string
38
     */
39
    public $value;
40
41
    /**
42
     * @var string
43
     */
44
    public $name;
45
46
    /**
47
     * @var bool
48
     */
49
    public $nohtml;
50
51
    /**
52
     * Constructor
53
     *
54
     * @param Form    $form            the form calling the editor selection
55
     * @param string  $name            editor name
56
     * @param string  $value           Pre-selected text value
57
     * @param boolean $nohtml          dohtml disabled
58
     * @param array   $allowed_editors allowed editors
59
     */
60 2
    public function __construct(
61
        Form $form,
62
        $name = 'editor',
63
        $value = null,
64
        $nohtml = false,
65
        $allowed_editors = array()
66
    ) {
67 2
        parent::__construct(\XoopsLocale::A_SELECT);
68 2
        $this->allowed_editors = $allowed_editors;
69 2
        $this->form = $form;
70 2
        $this->name = $name;
71 2
        $this->value = $value;
72 2
        $this->nohtml = $nohtml;
73 2
    }
74
75
    /**
76
     * defaultRender
77
     *
78
     * @return string rendered form element
79
     */
80 1
    public function defaultRender()
81
    {
82 1
        $editor_handler = \XoopsEditorHandler::getInstance();
83 1
        $editor_handler->allowed_editors = $this->allowed_editors;
84 1
        $option_select = new Select("", $this->name, $this->value);
85
        $onchangeCode = '"if(this.options[this.selectedIndex].value.length > 0 ){window.document.forms.'
86 1
            . $this->form->getName() . '.submit();}"';
87 1
        $option_select->set('onchange', $onchangeCode);
88 1
        $option_select->addOptionArray($editor_handler->getList($this->nohtml));
89 1
        $this->addElement($option_select);
90 1
        return parent::render();
91
    }
92
}
93