function Language::getDynamicPluginConfig

Same name and namespace in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language::getDynamicPluginConfig()
  2. 11.x core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language::getDynamicPluginConfig()

Overrides CKEditor5PluginDefault::getDynamicPluginConfig

File

core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php, line 65

Class

Language
CKEditor 5 Language plugin.

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.