class HTMLEditorAttributeRule (View source)

Rules used to define whether a given attribute or regex pattern of attributes is allowed in the content of an HTMLEditorField.

Each attribute rule is applied to a single HTMLEditorElementRule matching an element or a regex patter of elements.

Constants

VALUE_DEFAULT

VALUE_FORCED

VALUE_VALID

Methods

public static 
fromArray(string $name, array $ruleArray)

Returns a HTMLEditorAttributeRule based on an associative array defining the rule.

public
__construct(string $name, bool $nameIsPattern = false, null|array|string $value = null, string $valueType = HTMLEditorAttributeRule::VALUE_VALID)

No description

public
string
getName()

Get the name of the attribute(s) this rule applies to.

public
bool
getNameIsPattern()

Returns true if the value returned from getName() is a regex pattern.

public
string|null
getDefaultValue()

Get the default value the attribute(s) this rule applies to will be set to, if any.

public
string|null
getForcedValue()

Get the value the attribute(s) this rule applies to will be forced to, if any.

public
bool
hasForcedOrDefaultValue()

Get whether this attribute rule has a forced or default value.

public
array
getValidValues()

Get the set of values the attribute(s) this rule applies to is allowed to be set to.

public
setIsRequired(bool $isRequired)

Set whether the attribute(s) this rule applies to must be present for the element to be allowed.

public
bool
getIsRequired()

Get whether the attribute(s) this rule applies to must be present for the element to be allowed.

public
bool
isAttributeAllowed(DOMAttr $attribute)

Check wither the given attribute is allowed or not according to this rule.

Details

static HTMLEditorAttributeRule fromArray(string $name, array $ruleArray)

Returns a HTMLEditorAttributeRule based on an associative array defining the rule.

If the rule array is empty, the defaults apply.

Parameters

string $name
array $ruleArray

Return Value

HTMLEditorAttributeRule

__construct(string $name, bool $nameIsPattern = false, null|array|string $value = null, string $valueType = HTMLEditorAttributeRule::VALUE_VALID)

No description

Parameters

string $name
bool $nameIsPattern
null|array|string $value
string $valueType

string getName()

Get the name of the attribute(s) this rule applies to.

This can also be a regex pattern - in which case getNameIsPattern() should return true.

Return Value

string

bool getNameIsPattern()

Returns true if the value returned from getName() is a regex pattern.

Return Value

bool

string|null getDefaultValue()

Get the default value the attribute(s) this rule applies to will be set to, if any.

Return Value

string|null

string|null getForcedValue()

Get the value the attribute(s) this rule applies to will be forced to, if any.

A forced value will override any user-provided value.

Return Value

string|null

bool hasForcedOrDefaultValue()

Get whether this attribute rule has a forced or default value.

Return Value

bool

array getValidValues()

Get the set of values the attribute(s) this rule applies to is allowed to be set to.

If the array is empty, any value is valid.

Return Value

array

HTMLEditorAttributeRule setIsRequired(bool $isRequired)

Set whether the attribute(s) this rule applies to must be present for the element to be allowed.

Parameters

bool $isRequired

Return Value

HTMLEditorAttributeRule

bool getIsRequired()

Get whether the attribute(s) this rule applies to must be present for the element to be allowed.

Return Value

bool

bool isAttributeAllowed(DOMAttr $attribute)

Check wither the given attribute is allowed or not according to this rule.

Note that this method assumes this rule applies to the attribute - it does not check the name of the attribute as part of its conditional logic.

Parameters

DOMAttr $attribute

Return Value

bool