|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Form\Element; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Html5; |
|
8
|
|
|
use AbterPhp\Framework\Html\Attribute; |
|
9
|
|
|
use AbterPhp\Framework\Html\Helper\Attributes; |
|
10
|
|
|
use AbterPhp\Framework\Html\Helper\Tag as TagHelper; |
|
11
|
|
|
use AbterPhp\Framework\Html\Tag; |
|
12
|
|
|
|
|
13
|
|
|
class Textarea extends Input implements IElement |
|
14
|
|
|
{ |
|
15
|
|
|
public const CLASS_WYSIWYG = 'wysiwyg'; |
|
16
|
|
|
|
|
17
|
|
|
protected const DEFAULT_TAG = Html5::TAG_TEXTAREA; |
|
18
|
|
|
|
|
19
|
|
|
protected const DEFAULT_ROW = '3'; |
|
20
|
|
|
|
|
21
|
|
|
protected const PROTECTED_KEYS = [Html5::ATTR_ID, Html5::ATTR_NAME, Html5::ATTR_ROWS, Html5::ATTR_VALUE]; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Textarea constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $inputId |
|
27
|
|
|
* @param string $name |
|
28
|
|
|
* @param string $value |
|
29
|
|
|
* @param string[] $intents |
|
30
|
|
|
* @param array<string, Attribute>|null $attributes |
|
31
|
|
|
* @param string|null $tag |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct( |
|
34
|
|
|
string $inputId, |
|
35
|
|
|
string $name, |
|
36
|
|
|
string $value = '', |
|
37
|
|
|
array $intents = [], |
|
38
|
|
|
?array $attributes = null, |
|
39
|
|
|
?string $tag = null |
|
40
|
|
|
) { |
|
41
|
|
|
$attributes ??= []; |
|
42
|
|
|
$attributes = Attributes::addItem($attributes, Html5::ATTR_ID, $inputId); |
|
43
|
|
|
if (!in_array(Html5::ATTR_ROWS, $attributes)) { |
|
44
|
|
|
$attributes = Attributes::addItem($attributes, Html5::ATTR_ROWS, static::DEFAULT_ROW); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$attributes = Attributes::addItem($attributes, Html5::ATTR_NAME, $name); |
|
48
|
|
|
|
|
49
|
|
|
Tag::__construct(null, $intents, $attributes, $tag); |
|
50
|
|
|
|
|
51
|
|
|
$this->setValue($value); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __toString(): string |
|
58
|
|
|
{ |
|
59
|
|
|
$value = $this->attributes[Html5::ATTR_VALUE]->getValue(); |
|
60
|
|
|
|
|
61
|
|
|
$attributes = $this->attributes; |
|
62
|
|
|
unset($attributes[Html5::ATTR_VALUE]); |
|
63
|
|
|
|
|
64
|
|
|
return TagHelper::toString($this->tag, $value, $attributes); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|