final class HTMLRestrictionsUtilities (View source)

internal  
 

Utilities for interacting with HTML restrictions.

Constants

private WILDCARD_ELEMENT_METHODS

Wildcard types, and the methods that return tags the wildcard represents.

Methods

static array
toReadableElements(array $elements)

Formats HTML elements for display.

static array
allowedElementsStringToPluginElementsArray(string $elements_string)

Parses a HTML restrictions string with >=1 tags in an array of single tags.

static array
allowedElementsStringToHtmlFilterArray(string $elements_string)

Parses an HTML string into an array structured as expected by filter_html.

static array
cleanAllowedHtmlArray(array $elements)

Cleans unwanted artifacts from "allowed HTML" arrays.

static void
addAllowedAttributeToElements(array $elements, string $tag, string $attribute, array|true $value)

Adds allowed attributes to the elements array.

static array
diffAllowedElements(array $elements_array_1, array $elements_array_2)

Compares two HTML restrictions.

static array
allowedElementsStringToHtmlSupportConfig(string $elements_string)

Parses a HTML restrictions string into htmlSupport plugin config structure.

static array
getWildcardTags(string $wildcard)

Returns the tags that match the provided wildcard.

Details

static array toReadableElements(array $elements)

Formats HTML elements for display.

Parameters

array $elements

List of elements to format. The structure is the same as the allowed tags array documented in FilterInterface::getHTMLRestrictions().

Return Value

array

A formatted list; a string representation of the given HTML elements.

See also

FilterInterface::getHTMLRestrictions

static array allowedElementsStringToPluginElementsArray(string $elements_string)

Parses a HTML restrictions string with >=1 tags in an array of single tags.

Parameters

string $elements_string

A HTML restrictions string.

Return Value

array

A list of strings, with a HTML tag and potentially attributes in each.

static array allowedElementsStringToHtmlFilterArray(string $elements_string)

Parses an HTML string into an array structured as expected by filter_html.

Parameters

string $elements_string

A string of HTML tags, potentially with attributes.

Return Value

array

An elements array. The structure is the same as the allowed tags array documented in FilterInterface::getHTMLRestrictions().

See also

HTMLRestrictionsUtilities::WILDCARD_ELEMENT_METHODS Each key in this array represents a valid wildcard tag.
FilterHtml
FilterInterface::getHTMLRestrictions

static array cleanAllowedHtmlArray(array $elements)

Cleans unwanted artifacts from "allowed HTML" arrays.

Parameters

array $elements

An array of allowed elements. The structure is the same as the allowed tags array documented in FilterInterface::getHTMLRestrictions().

Return Value

array

The array without unwanted artifacts.

See also

FilterInterface::getHTMLRestrictions

static void addAllowedAttributeToElements(array $elements, string $tag, string $attribute, array|true $value)

Adds allowed attributes to the elements array.

Parameters

array $elements

The elements array. The structure is the same as the allowed tags array documented in FilterInterface::getHTMLRestrictions().

string $tag

The tag having its attributes configured.

string $attribute

The attribute being configured.

array|true $value

The attribute config value.

Return Value

void

See also

FilterInterface::getHTMLRestrictions

static array diffAllowedElements(array $elements_array_1, array $elements_array_2)

Compares two HTML restrictions.

The structure of the arrays is the same as the allowed tags array documented in FilterInterface::getHTMLRestrictions().

Parameters

array $elements_array_1

The array to compare from.

array $elements_array_2

The array to compare to.

Return Value

array

Returns an array with all the values in $elements_array_1 that are not present in $elements_array_1, including values that are FALSE

See also

FilterInterface::getHTMLRestrictions

static array allowedElementsStringToHtmlSupportConfig(string $elements_string)

Parses a HTML restrictions string into htmlSupport plugin config structure.

Parameters

string $elements_string

A HTML restrictions string.

Return Value

array

An array of allowed elements, structured in the manner expected by the CKEditor 5 htmlSupport plugin constructor.

See also

https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/features/general-html-support.html#configuration

static array getWildcardTags(string $wildcard)

Returns the tags that match the provided wildcard.

A wildcard tag in element config is a way of representing multiple tags with a single item, such as <$block> to represent all block tags. Each wildcard should have a corresponding callback method listed in WILDCARD_ELEMENT_METHODS that returns the set of tags represented by the wildcard.

Parameters

string $wildcard

The wildcard that represents multiple tags.

Return Value

array

An array of HTML tags.