class Language extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface, CKEditorPluginCssInterface (View source)

Defines the "language" plugin.

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
protected ModuleExtensionList $moduleList

The module list service.

from  CKEditorPluginBase

Methods

__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.

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.

getModuleList()

Gets the module list service.

string
getModulePath(string $module_name)

Gets the Drupal-root relative installation directory of a module.

bool
isInternal()

Indicates if this plugin is part of the optimized CKEditor build.

array
getDependencies(Editor $editor)

Returns a list of plugins this plugin requires.

array
getLibraries(Editor $editor)

Returns a list of libraries this plugin requires.

string|false
getFile()

Returns the Drupal root-relative file path to the plugin JavaScript file.

array
getConfig(Editor $editor)

Returns the additions to CKEDITOR.config for a specific CKEditor instance.

array
getButtons()

Returns the buttons that this plugin provides, along with metadata.

array
settingsForm(array $form, FormStateInterface $form_state, Editor $editor)

Returns a settings form to configure this CKEditor plugin.

string[]
getCssFiles(Editor $editor)

Retrieves enabled plugins' iframe instance CSS files.

Details

__construct(array $configuration, string $plugin_id, mixed $plugin_definition)

Constructs a \Drupal\Component\Plugin\PluginBase object.

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.

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.

protected ModuleExtensionList getModuleList()

Gets the module list service.

Return Value

ModuleExtensionList

The module extension list service.

protected string getModulePath(string $module_name)

Gets the Drupal-root relative installation directory of a module.

Parameters

string $module_name

The machine name of the module.

Return Value

string

The module installation directory.

Exceptions

InvalidArgumentException

See also

ExtensionList::getPath

bool isInternal()

Indicates if this plugin is part of the optimized CKEditor build.

Plugins marked as internal are implicitly loaded as part of CKEditor.

Return Value

bool

array getDependencies(Editor $editor)

Returns a list of plugins this plugin requires.

Parameters

Editor $editor

A configured text editor object.

Return Value

array

An unindexed array of plugin names this plugin requires. Each plugin is is identified by its annotated ID.

array getLibraries(Editor $editor)

Returns a list of libraries this plugin requires.

These libraries will be attached to the text_format element on which the editor is being loaded.

Parameters

Editor $editor

A configured text editor object.

Return Value

array

An array of libraries suitable for usage in a render API #attached property.

string|false getFile()

Returns the Drupal root-relative file path to the plugin JavaScript file.

Note: this does not use a Drupal library because this uses CKEditor's API.

Return Value

string|false

The Drupal root-relative path to the file, FALSE if an internal plugin.

array getConfig(Editor $editor)

Returns the additions to CKEDITOR.config for a specific CKEditor instance.

The editor's settings can be retrieved via $editor->getSettings(), but be aware that it may not yet contain plugin-specific settings, because the user may not yet have configured the form. If there are plugin-specific settings (verify with isset()), they can be found at

Parameters

Editor $editor

A configured text editor object.

Return Value

array

A keyed array, whose keys will end up as keys under CKEDITOR.config.

array getButtons()

Returns the buttons that this plugin provides, along with metadata.

The metadata is used by the CKEditor module to generate a visual CKEditor toolbar builder UI.

Return Value

array

An array of buttons that are provided by this plugin. This will only be used in the administrative section for assembling the toolbar. Each button should be keyed by its CKEditor button name (you can look up the button name up in the plugin.js file), and should contain an array of button properties, including:

  • label: A human-readable, translated button name.
  • image: An image for the button to be used in the toolbar.
  • image_rtl: If the image needs to have a right-to-left version, specify an alternative file that will be used in RTL editors.
  • image_alternative: If this button does not render as an image, specify an HTML string representing the contents of this button.
  • image_alternative_rtl: Similar to image_alternative, but a right-to-left version.
  • attributes: An array of HTML attributes which should be added to this button when rendering the button in the administrative section for assembling the toolbar.
  • multiple: Boolean value indicating if this button may be added multiple times to the toolbar. This typically is only applicable for dividers and group indicators.

array settingsForm(array $form, FormStateInterface $form_state, Editor $editor)

Returns a settings form to configure this CKEditor plugin.

If the plugin's behavior depends on extensive options and/or external data, then the implementing module can choose to provide a separate, global configuration page rather than per-text-editor settings. In that case, this form should provide a link to the separate settings page.

Parameters

array $form

An empty form array to be populated with a configuration form, if any.

FormStateInterface $form_state

The state of the entire filter administration form.

Editor $editor

A configured text editor object.

Return Value

array

A render array for the settings form.

string[] getCssFiles(Editor $editor)

Retrieves enabled plugins' iframe instance CSS files.

Note: this does not use a Drupal asset library because this CSS will be loaded by CKEditor, not by Drupal.

Parameters

Editor $editor

A configured text editor object.

Return Value

string[]

An array of CSS files. This is a flat list of file paths relative to the Drupal root.