public function HTMLRestrictions::toCKEditor5ElementsArray in Drupal 10
Transforms into the CKEditor 5 package metadata "elements" representation.
Return value
string[] A list of strings, with each string expressing an allowed element, structured in the way expected by the CKEditor 5 package metadata.
See also
https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing...
File
- core/
modules/ ckeditor5/ src/ HTMLRestrictions.php, line 1029
Class
- HTMLRestrictions
- Represents a set of HTML restrictions.
Namespace
Drupal\ckeditor5Code
public function toCKEditor5ElementsArray() : array {
$readable = [];
foreach ($this->elements as $tag => $attributes) {
$attribute_string = '';
if (is_array($attributes)) {
foreach ($attributes as $attribute_name => $attribute_values) {
if (is_array($attribute_values)) {
$attribute_values_string = implode(' ', array_keys($attribute_values));
$attribute_string .= "{$attribute_name}=\"{$attribute_values_string}\" ";
}
else {
// Special case: the global attribute `*` HTML tag.
// @see https://html.spec.whatwg.org/multipage/dom.html#global-attributes
// @see validateAllowedRestrictionsPhase2()
// @see validateAllowedRestrictionsPhase4()
if ($attribute_values === FALSE) {
assert($tag === '*');
continue;
}
$attribute_string .= "{$attribute_name} ";
}
}
}
// Special case: the global attribute `*` HTML tag.
// @see https://html.spec.whatwg.org/multipage/dom.html#global-attributes
// @see validateAllowedRestrictionsPhase2()
// @see validateAllowedRestrictionsPhase4()
if ($tag === '*' && empty(array_filter($attributes))) {
continue;
}
$joined = '<' . $tag . (!empty($attribute_string) ? ' ' . trim($attribute_string) : '') . '>';
array_push($readable, $joined);
}
assert(Inspector::assertAllStrings($readable));
return $readable;
}