You are here

public function Language::getConfig in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/ckeditor/src/Plugin/CKEditorPlugin/Language.php \Drupal\ckeditor\Plugin\CKEditorPlugin\Language::getConfig()

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

$settings = $editor
  ->getSettings();
$plugin_specific_settings = $settings['plugins'][$plugin_id];

Parameters

\Drupal\editor\Entity\Editor $editor: A configured text editor object.

Return value

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

Overrides CKEditorPluginInterface::getConfig

File

core/modules/ckeditor/src/Plugin/CKEditorPlugin/Language.php, line 48

Class

Language
Defines the "language" plugin.

Namespace

Drupal\ckeditor\Plugin\CKEditorPlugin

Code

public function getConfig(Editor $editor) {
  $language_list = [];
  $config = [
    'language_list' => 'un',
  ];
  $settings = $editor
    ->getSettings();
  if (isset($settings['plugins']['language'])) {
    $config = $settings['plugins']['language'];
  }
  $predefined_languages = $config['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.
  foreach ($predefined_languages as $langcode => $language) {
    $english_name = $language[0];
    $direction = empty($language[2]) ? NULL : $language[2];
    if ($direction === LanguageInterface::DIRECTION_RTL) {
      $language_list[$english_name] = $langcode . ':' . $english_name . ':rtl';
    }
    else {
      $language_list[$english_name] = $langcode . ':' . $english_name;
    }
  }

  // Sort on full language name.
  ksort($language_list);
  $config = [
    'language_list' => array_values($language_list),
  ];
  return $config;
}