class Language
CKEditor 5 Language plugin.
@internal Plugin classes are internal.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\ckeditor5\Plugin\CKEditor5PluginDefault implements \Drupal\ckeditor5\Plugin\CKEditor5PluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language implements \Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface uses \Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableTrait extends \Drupal\ckeditor5\Plugin\CKEditor5PluginDefault
 
 
 - class \Drupal\ckeditor5\Plugin\CKEditor5PluginDefault implements \Drupal\ckeditor5\Plugin\CKEditor5PluginInterface extends \Drupal\Core\Plugin\PluginBase
 
 - class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
 
Expanded class hierarchy of Language
1 file declares its use of Language
- LanguagePluginTest.php in core/
modules/ ckeditor5/ tests/ src/ Unit/ LanguagePluginTest.php  
397 string references to 'Language'
- AccountSettingsForm::buildForm in core/
modules/ user/ src/ AccountSettingsForm.php  - Form constructor.
 - AssetControllerBase::deliver in core/
modules/ system/ src/ Controller/ AssetControllerBase.php  - Generates an aggregate, given a filename.
 - block.block.umami_languageswitcher.yml in core/
profiles/ demo_umami/ config/ install/ block.block.umami_languageswitcher.yml  - core/profiles/demo_umami/config/install/block.block.umami_languageswitcher.yml
 - BlockContentTypeForm::form in core/
modules/ block_content/ src/ BlockContentTypeForm.php  - Gets the actual form array to be built.
 - BlockForm::buildVisibilityInterface in core/
modules/ block/ src/ BlockForm.php  - Helper function for building the visibility UI form.
 
File
- 
              core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5Plugin/ Language.php, line 27  
Namespace
Drupal\ckeditor5\Plugin\CKEditor5PluginView source
class Language extends CKEditor5PluginDefault implements CKEditor5PluginConfigurableInterface, ContainerFactoryPluginInterface {
  use CKEditor5PluginConfigurableTrait;
  
  /**
   * Language constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin ID for the plugin instance.
   * @param \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
   *   The language manager.
   * @param \Drupal\Core\Routing\RouteProviderInterface $routeProvider
   *   The route provider.
   */
  public function __construct(array $configuration, string $plugin_id, CKEditor5PluginDefinition $plugin_definition, protected LanguageManagerInterface $languageManager, protected RouteProviderInterface $routeProvider) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container->get('language_manager'), $container->get('router.route_provider'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor) : array {
    $languages = NULL;
    switch ($this->configuration['language_list']) {
      case 'site_configured':
        $configured_languages = $this->languageManager
          ->getLanguages();
        $languages = [];
        foreach ($configured_languages as $language) {
          $languages[$language->getId()] = [
            $language->getName(),
            '',
            $language->getDirection(),
          ];
        }
        break;
      case 'all':
        $languages = LanguageManager::getStandardLanguageList();
        break;
      case 'un':
        $languages = LanguageManager::getUnitedNationsLanguageList();
    }
    // Generate the language_list setting as expected by the CKEditor Language
    // plugin, but key the values by the full language name so that we can sort
    // them later on.
    $language_list = [];
    foreach ($languages as $langcode => $language) {
      $english_name = $language[0];
      $direction = empty($language[2]) ? NULL : $language[2];
      $language_list[$english_name] = [
        'title' => $english_name,
        'languageCode' => $langcode,
      ];
      if ($direction === LanguageInterface::DIRECTION_RTL) {
        $language_list[$english_name]['textDirection'] = 'rtl';
      }
    }
    // Sort on full language name.
    ksort($language_list);
    $dynamic_plugin_config = $static_plugin_config;
    $dynamic_plugin_config['language']['textPartLanguage'] = array_values($language_list);
    return $dynamic_plugin_config;
  }
  
  /**
   * {@inheritdoc}
   *
   * @see \Drupal\editor\Form\EditorImageDialog
   * @see editor_image_upload_settings_form()
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $configured = count($this->languageManager
      ->getLanguages());
    $predefined = count(LanguageManager::getStandardLanguageList());
    $united_nations = count(LanguageManager::getUnitedNationsLanguageList());
    $language_list_description_args = [
      ':united-nations-official' => 'https://www.un.org/en/sections/about-un/official-languages',
      '@count_predefined' => $predefined,
      '@count_united_nations' => $united_nations,
      '@count_configured' => $configured,
    ];
    // If Language is enabled, link to the configuration route.
    if ($this->routeProvider
      ->getRoutesByNames([
      'entity.configurable_language.collection',
    ])) {
      $language_list_description = $this->t('The list of languages in the CKEditor "Language" dropdown can present the <a href=":united-nations-official">@count_united_nations official languages of the UN</a>, all @count_predefined languages predefined in Drupal, or the <a href=":admin-configure-languages">@count_configured languages configured for this site</a>.', $language_list_description_args + [
        ':admin-configure-languages' => Url::fromRoute('entity.configurable_language.collection')->toString(),
      ]);
    }
    else {
      $language_list_description = $this->t('The list of languages in the CKEditor "Language" dropdown can present the <a href=":united-nations-official">@count_united_nations official languages of the UN</a>, all @count_predefined languages predefined in Drupal, or the languages configured for this site.', $language_list_description_args);
    }
    $form['language_list'] = [
      '#title' => $this->t('Language list'),
      '#title_display' => 'invisible',
      '#type' => 'select',
      '#options' => [
        'un' => $this->t("United Nations' official languages (@count)", [
          '@count' => $united_nations,
        ]),
        'all' => $this->t('Drupal predefined languages (@count)', [
          '@count' => $predefined,
        ]),
        'site_configured' => $this->t("Site-configured languages (@count)", [
          '@count' => $configured,
        ]),
      ],
      '#default_value' => $this->configuration['language_list'],
      '#description' => $language_list_description,
    ];
    return $form;
  }
  
  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }
  
  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['language_list'] = $form_state->getValue('language_list');
  }
  
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'language_list' => 'un',
    ];
  }
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides | 
|---|---|---|---|---|---|
| CKEditor5PluginConfigurableTrait::getConfiguration | public | function | |||
| CKEditor5PluginConfigurableTrait::setConfiguration | public | function | |||
| DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
| DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
| DependencySerializationTrait::__sleep | public | function | 2 | ||
| DependencySerializationTrait::__wakeup | public | function | #[\ReturnTypeWillChange] | 2 | |
| Language::buildConfigurationForm | public | function | Overrides PluginFormInterface::buildConfigurationForm | ||
| Language::create | public static | function | Creates an instance of the plugin. | Overrides ContainerFactoryPluginInterface::create | |
| Language::defaultConfiguration | public | function | Gets default configuration for this plugin. | Overrides ConfigurableInterface::defaultConfiguration | |
| Language::getDynamicPluginConfig | public | function | Allows a plugin to modify its static configuration. | Overrides CKEditor5PluginDefault::getDynamicPluginConfig | |
| Language::submitConfigurationForm | public | function | Form submission handler. | Overrides PluginFormInterface::submitConfigurationForm | |
| Language::validateConfigurationForm | public | function | Form validation handler. | Overrides PluginFormInterface::validateConfigurationForm | |
| Language::__construct | public | function | Language constructor. | Overrides CKEditor5PluginDefault::__construct | |
| MessengerTrait::$messenger | protected | property | The messenger. | 25 | |
| MessengerTrait::messenger | public | function | Gets the messenger. | 25 | |
| MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
| PluginBase::$configuration | protected | property | Configuration information passed into the plugin. | 1 | |
| PluginBase::$pluginDefinition | protected | property | The plugin implementation definition. | 1 | |
| PluginBase::$pluginId | protected | property | The plugin ID. | ||
| PluginBase::DERIVATIVE_SEPARATOR | constant | A string which is used to separate base plugin IDs from the derivative ID. | |||
| PluginBase::getBaseId | public | function | Gets the base_plugin_id of the plugin instance. | Overrides DerivativeInspectionInterface::getBaseId | |
| PluginBase::getDerivativeId | public | function | Gets the derivative_id of the plugin instance. | Overrides DerivativeInspectionInterface::getDerivativeId | |
| PluginBase::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | Overrides PluginInspectionInterface::getPluginDefinition | 2 | 
| PluginBase::getPluginId | public | function | Gets the plugin ID of the plugin instance. | Overrides PluginInspectionInterface::getPluginId | |
| PluginBase::isConfigurable | public | function | Determines if the plugin is configurable. | ||
| StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
| StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
| StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
| StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
| StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
| StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.