depage-forms
v2.0.0
html forms made easy
Toggle main menu visibility
Loading...
Searching...
No Matches
Richtext.php
Go to the documentation of this file.
1
<?php
2
10
11
namespace
Depage\HtmlForm\Elements;
12
38
class
Richtext
extends
Textarea
39
{
43
public
$stylesheet
=
null
;
44
48
public
$allowedTags
= [];
49
53
public
$autogrow
=
true
;
54
64
protected
function
setDefaults
(): void
65
{
66
parent::setDefaults();
67
68
$this->defaults[
'rows'
] =
null
;
69
$this->defaults[
'cols'
] =
null
;
70
$this->defaults[
'stylesheet'
] =
null
;
71
$this->defaults[
'autogrow'
] =
true
;
72
$this->defaults[
'allowedTags'
] = [
73
// inline elements
74
"a"
,
75
"b"
,
76
"strong"
,
77
"i"
,
78
"em"
,
79
"small"
,
80
81
// block elements
82
"p"
,
83
"br"
,
84
"h1"
,
85
"h2"
,
86
"ul"
,
87
"ol"
,
88
"li"
,
89
];
90
}
91
95
protected
function
htmlDataAttributes
(): string
96
{
97
$options = [];
98
$options[
'stylesheet'
] =
$this->stylesheet
;
99
$options[
'allowedTags'
] =
$this->allowedTags
;
100
101
$this->dataAttr[
'richtext-options'
] = json_encode($options);
102
103
return
parent::htmlDataAttributes();
104
}
105
114
public
function
isEmpty
(): bool
115
{
116
return
empty(trim(strip_tags($this->value)));
117
}
118
124
protected
function
htmlValue
(): string
125
{
126
if
($this->value ===
null
) {
127
$htmlDOM = $this->
parseHtml
($this->defaultValue);
128
}
else
{
129
$htmlDOM =
$this->value
;
130
}
131
132
$html = (string) $htmlDOM;
133
134
return
$this->
htmlEscape
($html);
135
}
136
141
protected
function
typeCastValue
(): void
142
{
143
if
(is_string($this->value)) {
144
$this->value = $this->
parseHtml
($this->value);
145
}
146
}
147
154
protected
function
parseHtml
(
string
$html): \
Depage
\
HtmlForm
\
Abstracts
\
HtmlDom
155
{
156
if
($this->normalize && class_exists(
"\\Normalizer"
)) {
157
$html = \Normalizer::normalize($html);
158
}
159
160
$htmlDOM = new \Depage\HtmlForm\Abstracts\HtmlDom();
161
162
$htmlDOM->loadHTML($html);
163
$htmlDOM->cleanHTML($this->allowedTags);
164
165
if
($this->maxlength) {
166
$htmlDOM->cutToMaxlength($this->maxlength);
167
}
168
169
return
$htmlDOM;
170
}
171
}
172
173
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Depage\HtmlForm\Abstracts\Element\htmlEscape
htmlEscape(array|string $options=[])
Escapes HTML in strings and arrays of strings.
Definition
Element.php:263
Depage\HtmlForm\Abstracts\HtmlDom
DOMDocument for html-content.
Definition
HtmlDom.php:19
Depage\HtmlForm\Abstracts\Input\$value
$value
Input elements's value.
Definition
Input.php:124
Depage\HtmlForm\Elements\Richtext
HTML richtext element.
Definition
Richtext.php:39
Depage\HtmlForm\Elements\Richtext\$stylesheet
$stylesheet
stylesheet
Definition
Richtext.php:43
Depage\HtmlForm\Elements\Richtext\parseHtml
parseHtml(string $html)
Parses html-string into htmlDOM.
Definition
Richtext.php:154
Depage\HtmlForm\Elements\Richtext\$autogrow
$autogrow
autogrow
Definition
Richtext.php:53
Depage\HtmlForm\Elements\Richtext\typeCastValue
typeCastValue()
Converts value into htmlDOM.
Definition
Richtext.php:141
Depage\HtmlForm\Elements\Richtext\htmlDataAttributes
htmlDataAttributes()
Returns dataAttr escaped as attribute string.
Definition
Richtext.php:95
Depage\HtmlForm\Elements\Richtext\$allowedTags
$allowedTags
allowedTags
Definition
Richtext.php:48
Depage\HtmlForm\Elements\Richtext\htmlValue
htmlValue()
Returns HTML-rendered element value.
Definition
Richtext.php:124
Depage\HtmlForm\Elements\Richtext\setDefaults
setDefaults()
collects initial values across subclasses
Definition
Richtext.php:64
Depage\HtmlForm\Elements\Richtext\isEmpty
isEmpty()
says wether the element value is empty
Definition
Richtext.php:114
Depage\HtmlForm\Elements\Textarea
HTML textarea element.
Definition
Textarea.php:36
Depage\HtmlForm\HtmlForm
main interface to users
Definition
HtmlForm.php:132
Depage\HtmlForm\Abstracts
Abstract element classes.
Definition
Container.php:11
Depage
depage cms
Elements
Richtext.php
Generated on
for depage-forms by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net