Skip to content
Snippets Groups Projects

Issue #3273986: Third option for the CKEditor 4 "Language" button: `configured` (in addition to `un` and `all`)

Closed Issue #3273986: Third option for the CKEditor 4 "Language" button: `configured` (in addition to `un` and `all`)
6 unresolved threads
6 unresolved threads

This is !3328 rebased for 11.x, which I believe we have to target now that 10.1.0 is released?

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
44
45 /**
46 * Language constructor.
47 *
48 * @param array $configuration
49 * A configuration array containing information about the plugin instance.
50 * @param string $plugin_id
51 * The plugin_id for the plugin instance.
52 * @param \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition $plugin_definition
53 * The plugin implementation definition.
54 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
55 * The language manager.
56 * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
57 * The route provider.
58 */
59 public function __construct(array $configuration, string $plugin_id, CKEditor5PluginDefinition $plugin_definition, LanguageManagerInterface $language_manager, RouteProviderInterface $route_provider) {
  • 85 $languages = [];
    86 foreach ($configured_languages as $language) {
    87 $languages[$language->getId()] = [
    88 $language->getName(),
    89 '',
    90 $language->getDirection(),
    91 ];
    92 }
    93 break;
    94
    95 case 'all':
    96 $languages = LanguageManager::getStandardLanguageList();
    97 break;
    98
    99 case 'un':
    100 default:
  • 146 $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()]);
    147 }
    148 else {
    149 $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);
    150 }
    151
    64 152 $form['language_list'] = [
    65 153 '#title' => $this->t('Language list'),
    66 154 '#title_display' => 'invisible',
    67 155 '#type' => 'select',
    68 156 '#options' => [
    69 'un' => $this->t("United Nations' official languages"),
    70 'all' => $this->t('All @count languages', ['@count' => count($predefined_languages)]),
    157 'un' => $this->t("United Nations' official languages (@count)", ['@count' => $united_nations]),
    158 'all' => $this->t('Drupal predefined languages (@count)', ['@count' => $predefined]),
    159 'site_configured' => $this->t("Site configured languages (@count)", ['@count' => $configured]),
  • added 1 commit

    • 44408083 - 3273986-ckeditor5-enabled-languages-11.x

    Compare with previous version

  • added 1 commit

    • 7bd5d37b - 3273986-ckeditor5-enabled-languages-11.x

    Compare with previous version

  • Wim Leers
    Wim Leers @wimleers started a thread on the diff
  • 71 $languages[$language->getId()] = [
    72 $language->getName(),
    73 '',
    74 $language->getDirection(),
    75 ];
    76 }
    77 break;
    78
    79 case 'all':
    80 $languages = LanguageManager::getStandardLanguageList();
    81 break;
    82
    83 case 'un':
    84 default:
    85 $languages = LanguageManager::getUnitedNationsLanguageList();
    86 }
    • Comment on lines +66 to +86

      I'd still like to see the default disappear. To fix the PHPStan complaint, we can do this:

      Suggested change
      Applied
      66 switch ($this->configuration['language_list']) {
      67 case 'site_configured':
      68 $configured_languages = $this->languageManager->getLanguages();
      69 $languages = [];
      70 foreach ($configured_languages as $language) {
      71 $languages[$language->getId()] = [
      72 $language->getName(),
      73 '',
      74 $language->getDirection(),
      75 ];
      76 }
      77 break;
      78
      79 case 'all':
      80 $languages = LanguageManager::getStandardLanguageList();
      81 break;
      82
      83 case 'un':
      84 default:
      85 $languages = LanguageManager::getUnitedNationsLanguageList();
      86 }
      66 $languages = NULL;
      67 switch ($this->configuration['language_list']) {
      68 case 'site_configured':
      69 $configured_languages = $this->languageManager->getLanguages();
      70 $languages = [];
      71 foreach ($configured_languages as $language) {
      72 $languages[$language->getId()] = [
      73 $language->getName(),
      74 '',
      75 $language->getDirection(),
      76 ];
      77 }
      78 break;
      79
      80 case 'all':
      81 $languages = LanguageManager::getStandardLanguageList();
      82 break;
      83
      84 case 'un':
      85 $languages = LanguageManager::getUnitedNationsLanguageList();
      86 }
    • Please register or sign in to reply
  • 218 220 $page = $this->getSession()->getPage();
    219 221 $assert_session = $this->assertSession();
    220 222
    223 $this->languageOfPartsPluginInitialConfigurationHelper($page, $assert_session);
    224
    225 // Test for "United Nations' official languages" option.
    226 $languages = LanguageManager::getUnitedNationsLanguageList();
    227 $this->languageOfPartsPluginConfigureLanguageListHelper($page, $assert_session, 'un');
    228 $this->languageOfPartsPluginTestHelper($page, $assert_session, $languages);
    229
    230 // Test for "Drupal predefined languages" option.
    231 $languages = LanguageManager::getStandardLanguageList();
    232 $this->languageOfPartsPluginConfigureLanguageListHelper($page, $assert_session, 'all');
    233 $this->languageOfPartsPluginTestHelper($page, $assert_session, $languages);
    234
    235 // Test for "Site configured languages" option.
  • Wim Leers added 1 commit

    added 1 commit

    • 7c0e4f7b - PHPStan compliance nit + language nit.

    Compare with previous version

  • 59 );
    60 }
    61
    25 62 /**
    26 63 * {@inheritdoc}
    27 64 */
    28 65 public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor): array {
    29 $predefined_languages = $this->configuration['language_list'] === 'all' ?
    30 LanguageManager::getStandardLanguageList() :
    31 LanguageManager::getUnitedNationsLanguageList();
    66 $languages = NULL;
    67 switch ($this->configuration['language_list']) {
    68 case 'site_configured':
    69 $configured_languages = $this->languageManager->getLanguages();
    70 $languages = [];
    71 foreach ($configured_languages as $language) {
    • Does it actually make sense to return all configure languages including the current language? Wouldn't it make sense for majority of the use cases to exclude the current language from the list?

    • I concur that the current page language could be redundant to assign where the HTML document has a language attribute assigned, and Declaring language in HTML suggests to only assign languages which are not the default language of the document. However, we should consider the cases of nesting of languages (eg an English word in a Māori sentence in an English document), that documents (nodes) may have undefined languages, and that Drupal has multiple layers of editing (embeds, blocks, pages, nodes, etc).

      While that might be an interesting technical challenge, I don't think the diversion of implementing it should stand in the way of delivering this useful functionality, which Drupal currently does not support. There's a bug here that today prevents useful functionality for sites in languages not well-supported by Drupal.

      Let's fix that, and consider that in a follow up issue if you wish to do so?

      Edited by Chris Burgess
    • Please register or sign in to reply
  • closed

  • Please register or sign in to reply
    Loading