You are here

public function Language::getDynamicPluginConfig in Drupal 10

File

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

Class

Language
CKEditor 5 Language plugin.

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin

Code

public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor) : array {
  $predefined_languages = $this->configuration['language_list'] === 'all' ? LanguageManager::getStandardLanguageList() : 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 ($predefined_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;
}