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

TextArea::defaultRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
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
 * TextArea - a text area element
16
 *
17
 * @category  Xoops\Form\TextArea
18
 * @package   Xoops\Form
19
 * @author    Kazumi Ono <[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 TextArea extends Element
25
{
26
    /**
27
     * Constructor
28
     *
29
     * @param string|array $caption     Caption or array of all attributes
30
     * @param string       $name        name
31
     * @param string       $value       initial content
32
     * @param integer      $rows        number of rows
33
     * @param integer      $cols        number of columns
34
     * @param string       $placeholder placeholder for this element.
35
     */
36 9
    public function __construct($caption, $name = null, $value = "", $rows = 5, $cols = 50, $placeholder = '')
37
    {
38 9
        if (is_array($caption)) {
39 1
            parent::__construct($caption);
40 1
            $this->setIfNotSet('rows', 5);
41 1
            $this->setIfNotSet('cols', 50);
42
        } else {
43 9
            parent::__construct([]);
44 9
            $this->setWithDefaults('caption', $caption, '');
45 9
            $this->setWithDefaults('name', $name, 'name_error');
46 9
            $this->setWithDefaults('rows', $rows, 5);
47 9
            $this->setWithDefaults('cols', $cols, 50);
48 9
            $this->setWithDefaults('value', $value, '');
49 9
            $this->setIfNotEmpty('placeholder', $placeholder);
50
        }
51 9
    }
52
53
    /**
54
     * get number of rows
55
     *
56
     * @return int
57
     */
58 2
    public function getRows()
59
    {
60 2
        return (int) $this->get('rows');
61
    }
62
63
    /**
64
     * Get number of columns
65
     *
66
     * @return int
67
     */
68 2
    public function getCols()
69
    {
70 2
        return (int) $this->get('cols');
71
    }
72
73
    /**
74
     * Get placeholder for this element
75
     *
76
     * @return string
77
     */
78 1
    public function getPlaceholder()
79
    {
80 1
        return (string) $this->get('placeholder');
81
    }
82
83
    /**
84
     * defaultRender
85
     *
86
     * @return string rendered form element
87
     */
88 3
    public function defaultRender()
89
    {
90 3
        $this->suppressRender(['value']);
91
        $attributes = $this->renderAttributeString();
92 3
        return '<textarea ' . $attributes . ' ' . $this->getExtra() .' >'
93
            . $this->getValue() . '</textarea>';
94 3
    }
95
}
96