getJSSettings example

$plugin = $this->createInstance($editor->getEditor());
      $plugin_definition = $plugin->getPluginDefinition();

      // Libraries.       $attachments['library'] = array_merge($attachments['library']$plugin->getLibraries($editor));

      // Format-specific JavaScript settings.       $settings['editor']['formats'][$format_id] = [
        'format' => $format_id,
        'editor' => $editor->getEditor(),
        'editorSettings' => $plugin->getJSSettings($editor),
        'editorSupportsContentFiltering' => $plugin_definition['supports_content_filtering'],
        'isXssSafe' => $plugin_definition['is_xss_safe'],
      ];
    }

    // Allow other modules to alter all JavaScript settings.     $this->moduleHandler->alter('editor_js_settings', $settings);

    if (empty($attachments['library']) && empty($settings)) {
      return [];
    }

    

  public function test(string $drupal_langcode, string $cke5_langcode, bool $is_missing_mapping = FALSE): void {
    $editor = Editor::load('basic_html');

    ConfigurableLanguage::createFromLangcode($drupal_langcode)->save();
    $this->config('system.site')->set('default_langcode', $drupal_langcode)->save();

    if ($is_missing_mapping) {
      // CKEditor 5's UI language falls back to English, until the language       // mapping is expanded.       $settings = $this->ckeditor5->getJSSettings($editor);
      $this->assertSame('en', $settings['language']['ui']);

      // Expand the language mapping.       $config = $this->config('language.mappings');
      $mapping = $config->get('map');
      $mapping += [$cke5_langcode => $drupal_langcode];
      $config->set('map', $mapping)->save();
    }

    $settings = $this->ckeditor5->getJSSettings($editor);
    $this->assertSame($cke5_langcode$settings['language']['ui']);
  }
$this->assertSame([]$this->editorManager->getAttachments([]), 'No attachments when one text editor is enabled and retrieving attachments for zero text formats.');
    $expected = [
      'library' => [
        0 => 'editor_test/unicorn',
      ],
      'drupalSettings' => [
        'editor' => [
          'formats' => [
            'full_html' => [
              'format'  => 'full_html',
              'editor' => 'unicorn',
              'editorSettings' => $unicorn_plugin->getJSSettings($editor),
              'editorSupportsContentFiltering' => TRUE,
              'isXssSafe' => FALSE,
            ],
          ],
        ],
      ],
    ];
    $this->assertSame($expected$this->editorManager->getAttachments(['filtered_html', 'full_html']), 'Correct attachments when one text editor is enabled and retrieving attachments for multiple text formats.');

    // Case 4: a text editor available associated, but now with its JS settings     // being altered via hook_editor_js_settings_alter().
Home | Imprint | This part of the site doesn't use cookies.