TextFormat
class TextFormat extends RenderElement (View source)
Provides a text format render element.
Properties:
-
base_type: The form element #type to use for the 'value' element.
'textarea' by default.
-
format: (optional) The text format ID to preselect. If omitted, the
default format for the current user will be used.
-
allowed_formats: (optional) An array of text format IDs that are available
for this element. If omitted, all text formats that the current user has access to will be allowed.
Usage Example:
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 |
Methods
Constructs a \Drupal\Component\Plugin\PluginBase object.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Sets a form element's class attribute.
Adds members of this group as actual elements for rendering.
Form element processing handler for the #ajax form property.
Adds Ajax information about an element to communicate with JavaScript.
Arranges elements into groups.
Returns the element properties for this element.
Expands an element into a base element with text format selector attached.
Render API callback: Hides the field value of 'text_format' elements.
Wraps the current user.
Wraps the config factory.
Wraps the element info service.
Details
__construct(array $configuration, string $plugin_id, mixed $plugin_definition)
Constructs a \Drupal\Component\Plugin\PluginBase object.
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.
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
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
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.
MessengerInterface
messenger()
Gets the messenger.
static
setAttributes(array $element, array $class = [])
Sets a form element's class attribute.
Adds 'required' and 'error' classes as needed.
static array
preRenderGroup(array $element)
Adds members of this group as actual elements for rendering.
static array
processAjaxForm(array $element, FormStateInterface $form_state, array $complete_form)
Form element processing handler for the #ajax form property.
This method is useful for non-input elements that can be used in and outside the context of a form.
static array
preRenderAjaxForm(array $element)
Adds Ajax information about an element to communicate with JavaScript.
If #ajax is set on an element, this additional JavaScript is added to the page header to attach the Ajax behaviors. See ajax.js for more information.
static array
processGroup(array $element, FormStateInterface $form_state, array $complete_form)
Arranges elements into groups.
This method is useful for non-input elements that can be used in and outside the context of a form.
array
getInfo()
Returns the element properties for this element.
static array
processFormat(array $element, FormStateInterface $form_state, array $complete_form)
Expands an element into a base element with text format selector attached.
The form element will be expanded into two separate form elements, one holding the original element, and the other holding the text format selector:
- value: Holds the original element, having its #type changed to the value of #base_type or 'textarea' by default.
- format: Holds the text format details and the text format selection, using the text format ID specified in #format or the user's default format by default, if NULL.
The resulting value for the element will be an array holding the value and the format. For example, the value for the body element will be:
static array
accessDeniedCallback(array $element)
Render API callback: Hides the field value of 'text_format' elements.
To not break form processing and previews if a user does not have access to a stored text format, the expanded form elements in \Drupal\filter\Element\TextFormat::processFormat() are forced to take over the stored #default_values for 'value' and 'format'. However, to prevent the unfiltered, original #value from being displayed to the user, we replace it with a friendly notice here.
static protected
currentUser()
Wraps the current user.
\Drupal\Core\Session\AccountInterface
static protected ConfigFactoryInterface
configFactory()
Wraps the config factory.
static protected ElementInfoManagerInterface
elementInfo()
Wraps the element info service.