class FilterCaption extends FilterBase implements ContainerFactoryPluginInterface (View source)

Provides a filter to caption elements.

When used in combination with the filter_align filter, this must run last.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Provides dependency injection friendly methods for serialization.

Provides a trait for the messenger service.

Constants

DERIVATIVE_SEPARATOR

A string which is used to separate base plugin IDs from the derivative ID.

Properties

protected string $pluginId

The plugin_id.

from  PluginBase
protected array $pluginDefinition

The plugin implementation definition.

from  PluginBase
protected array $configuration

Configuration information passed into the plugin.

from  PluginBase
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected MessengerInterface $messenger

The messenger.

from  MessengerTrait
string $provider

The name of the provider that owns this filter.

from  FilterBase
bool $status

A Boolean indicating whether this filter is enabled.

from  FilterBase
int $weight

The weight of this filter compared to others in a filter collection.

from  FilterBase
array $settings

An associative array containing the configured settings of this filter.

from  FilterBase
protected FilterPluginManager $filterManager

Filter manager.

Methods

__construct(array $configuration, string $plugin_id, mixed $plugin_definition, FilterPluginManager $filter_manager = NULL)

Constructs a new FilterCaption.

string
getPluginId()

Gets the plugin_id of the plugin instance.

string
getBaseId()

Gets the base_plugin_id of the plugin instance.

string|null
getDerivativeId()

Gets the derivative_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

bool
isConfigurable()

Determines if the plugin is configurable.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

array
getConfiguration()

Gets this plugin's configuration.

array
defaultConfiguration()

Gets default configuration for this plugin.

array
calculateDependencies()

Calculates dependencies for the configured plugin.

int
getType()

Returns the processing type of this filter plugin.

string
getLabel()

Returns the administrative label for this filter plugin.

string
getDescription()

Returns the administrative description for this filter plugin.

array
settingsForm(array $form, FormStateInterface $form_state)

Generates a filter's settings form.

string
prepare(string $text, string $langcode)

Prepares the text for processing.

array|false
getHTMLRestrictions()

Returns HTML allowed by this filter's configuration.

string|null
tips(bool $long = FALSE)

Generates a filter's tip.

create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

process(string $text, string $langcode)

Performs the filter processing.

Details

__construct(array $configuration, string $plugin_id, mixed $plugin_definition, FilterPluginManager $filter_manager = NULL)

Constructs a new FilterCaption.

Parameters

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin_id for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

FilterPluginManager $filter_manager

Filter plugin manager.

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

string getBaseId()

Gets the base_plugin_id of the plugin instance.

Return Value

string

The base_plugin_id of the plugin instance.

string|null getDerivativeId()

Gets the derivative_id of the plugin instance.

Return Value

string|null

The derivative_id of the plugin instance NULL otherwise.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

bool isConfigurable()

Determines if the plugin is configurable.

Return Value

bool

A boolean indicating whether the plugin is configurable.

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

Parameters

array $configuration

An associative array containing the plugin's configuration.

array getConfiguration()

Gets this plugin's configuration.

Return Value

array

An array of this plugin's configuration.

array defaultConfiguration()

Gets default configuration for this plugin.

Return Value

array

An associative array with the default configuration.

array calculateDependencies()

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code array( 'config' => array('user.role.anonymous', 'user.role.authenticated'), 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), 'module' => array('node', 'user'), 'theme' => array('seven'), ); @endcode

int getType()

Returns the processing type of this filter plugin.

Return Value

int

One of:

  • FilterInterface::TYPE_MARKUP_LANGUAGE
  • FilterInterface::TYPE_HTML_RESTRICTOR
  • FilterInterface::TYPE_TRANSFORM_REVERSIBLE
  • FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE

string getLabel()

Returns the administrative label for this filter plugin.

Return Value

string

string getDescription()

Returns the administrative description for this filter plugin.

Return Value

string

array settingsForm(array $form, FormStateInterface $form_state)

Generates a filter's settings form.

Parameters

array $form

A minimally prepopulated form array.

FormStateInterface $form_state

The state of the (entire) configuration form.

Return Value

array

The $form array with additional form elements for the settings of this filter. The submitted form values should match $this->settings.

string prepare(string $text, string $langcode)

Prepares the text for processing.

Filters should not use the prepare method for anything other than escaping, because that would short-circuit the control the user has over the order in which filters are applied.

Parameters

string $text

The text string to be filtered.

string $langcode

The language code of the text to be filtered.

Return Value

string

The prepared, escaped text.

array|false getHTMLRestrictions()

Returns HTML allowed by this filter's configuration.

May be implemented by filters of the FilterInterface::TYPE_HTML_RESTRICTOR type, this won't be used for filters of other types; they should just return FALSE.

This callback function is only necessary for filters that strip away HTML tags (and possibly attributes) and allows other modules to gain insight in a generic manner into which HTML tags and attributes are allowed by a format.

Return Value

array|false

A nested array with either of the following keys:

  • 'allowed': (optional) the allowed tags as keys, and for each of those tags (keys) either of the following values:
    • TRUE to indicate any attribute is allowed
    • FALSE to indicate no attributes are allowed
    • an array to convey attribute restrictions: the keys must be attribute names (which may use a wildcard, e.g. "data-*"), the possible values are similar to the above:
      • TRUE to indicate any attribute value is allowed
      • FALSE to indicate the attribute is forbidden
      • an array to convey attribute value restrictions: the key must be attribute values (which may use a wildcard, e.g. "xsd:*"), the possible values are TRUE or FALSE: to mark the attribute value as allowed or forbidden, respectively
  • 'forbidden_tags': (optional) the forbidden tags

There is one special case: the "wildcard tag", "*": any attribute restrictions on that pseudotag apply to all tags.

If no restrictions apply, then FALSE must be returned.

Here is a concrete example, for a very granular filter: @code array( 'allowed' => array( // Allows any attribute with any value on the

tag. 'div' => TRUE, // Allows no attributes on the

tag. 'p' => FALSE, // Allows the following attributes on the tag: // - 'href', with any value; // - 'rel', with the value 'nofollow' value. 'a' => array( 'href' => TRUE, 'rel' => array('nofollow' => TRUE), ), // Only allows the 'src' and 'alt' attributes on the tag, // with any value. 'img' => array( 'src' => TRUE, 'alt' => TRUE, ), // Allow RDFa on tags, using only the dc, foaf, xsd and sioc // vocabularies/namespaces. 'span' => array( 'property' => array('dc:' => TRUE, 'foaf:' => TRUE), 'datatype' => array('xsd:' => TRUE), 'rel' => array('sioc:' => TRUE), ), // Forbid the 'style' and 'on' ('onClick' etc.) attributes on any // tag. '' => array( 'style' => FALSE, 'on*' => FALSE, ), ) ) @endcode

A simpler example, for a very coarse filter: @code array( 'forbidden_tags' => array('iframe', 'script') ) @endcode

The simplest example possible: a filter that doesn't allow any HTML: @code array( 'allowed' => array() ) @endcode

And for a filter that applies no restrictions, i.e. allows any HTML: @code FALSE @endcode

string|null tips(bool $long = FALSE)

Generates a filter's tip.

A filter's tips should be informative and to the point. Short tips are preferably one-liners.

Parameters

bool $long

Whether this callback should return a short tip to display in a form (FALSE), or whether a more elaborate filter tips should be returned for template_preprocess_filter_tips() (TRUE).

Return Value

string|null

Translated text to display as a tip, or NULL if this filter has no tip.

static ContainerFactoryPluginInterface create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

Parameters

ContainerInterface $container

The container to pull out services used in the plugin.

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin ID for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

Return Value

ContainerFactoryPluginInterface

Returns an instance of this plugin.

FilterProcessResult process(string $text, string $langcode)

Performs the filter processing.

Parameters

string $text

The text string to be filtered.

string $langcode

The language code of the text to be filtered.

Return Value

FilterProcessResult

The filtered text, wrapped in a FilterProcessResult object, and possibly with associated assets, cacheability metadata and placeholders.