Drupal\helper\TextFormat
Helper service for modifying text formats.
Methods
Name | Description |
---|---|
addTag | Add a tag to the HTML restrictions for specific formats, or all. |
isAttributeAllowed | Checks if a tag attribute is allowed. |
isTagAllowed | Checks if a tag is allowed. |
removeTag | Remove a tag and all its attributes from the HTML restrictions. |
removeTagAttributes | Remove a tag's attributes from the HTML restrictions for formats. |
TextFormat::addTag
Description
public addTag (\Drupal\filter\FilterFormatInterface $format, string $tag, array $attributes)
Add a tag to the HTML restrictions for specific formats, or all.
Parameters
(\Drupal\filter\FilterFormatInterface) $format
: The filter format.(string) $tag
: The tag name to add, without enclosing braces. Example: span.(array) $attributes
: (Optional) An array of attributes to add to the tag.
Return Values
void
TextFormat::isAttributeAllowed
Description
public isAttributeAllowed (\Drupal\filter\FilterFormatInterface $format, string $tag, string $attribute)
Checks if a tag attribute is allowed.
Parameters
(\Drupal\filter\FilterFormatInterface) $format
: The text format.(string) $tag
: The HTML tag name or '*' to check this global allowed attributes.(string) $attribute
: The optional attribute to check for.
Return Values
bool|null
A boolean if the tag is allowed or not. A NULL result is possible when
checking the global allowed attributes and there is no match found.
TextFormat::isTagAllowed
Description
public isTagAllowed (\Drupal\filter\FilterFormatInterface $format, string $tag)
Checks if a tag is allowed.
Parameters
(\Drupal\filter\FilterFormatInterface) $format
: The text format.(string) $tag
: The HTML tag name.
Return Values
bool
TRUE if the tag is allowed by the text format, or FALSE otherwise.
TextFormat::removeTag
Description
public removeTag (\Drupal\filter\FilterFormatInterface $format, string $tag)
Remove a tag and all its attributes from the HTML restrictions.
Parameters
(\Drupal\filter\FilterFormatInterface) $format
: The filter format.(string) $tag
: The tag name to remove, without enclosing braces. Example: span.
Return Values
void
TextFormat::removeTagAttributes
Description
public removeTagAttributes (\Drupal\filter\FilterFormatInterface $format, string $tag, array $attributes)
Remove a tag's attributes from the HTML restrictions for formats.
Parameters
(\Drupal\filter\FilterFormatInterface) $format
: The filter format.(string) $tag
: The tag name from which to remove attributes, without enclosing braces.(array) $attributes
: An array of attributes to remove from the tag.
Return Values
void