function MediaLibrary::getDynamicPluginConfig

Same name in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/MediaLibrary.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\MediaLibrary::getDynamicPluginConfig()
  2. 10 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/MediaLibrary.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\MediaLibrary::getDynamicPluginConfig()

Overrides CKEditor5PluginDefault::getDynamicPluginConfig

File

core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/MediaLibrary.php, line 68

Class

MediaLibrary
CKEditor 5 Media Library plugin.

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin

Code

public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor) : array {
    $media_type_ids = $this->mediaTypeStorage
        ->getQuery()
        ->execute();
    // Making the title for editor drupal media embed translatable.
    $static_plugin_config['drupalMedia']['dialogSettings']['title'] = $this->t('Add or select media');
    if ($editor->hasAssociatedFilterFormat()) {
        $media_embed_filter = $editor->getFilterFormat()
            ->filters()
            ->get('media_embed');
        // Optionally limit the allowed media types based on the MediaEmbed
        // setting. If the setting is empty, do not limit the options.
        if (!empty($media_embed_filter->settings['allowed_media_types'])) {
            $media_type_ids = array_intersect_key($media_type_ids, $media_embed_filter->settings['allowed_media_types']);
        }
    }
    if (in_array('image', $media_type_ids, TRUE)) {
        // Move image to first position.
        // This workaround can be removed once this issue is fixed:
        // @see https://www.drupal.org/project/drupal/issues/3073799
        array_unshift($media_type_ids, 'image');
        $media_type_ids = array_unique($media_type_ids);
    }
    $state = MediaLibraryState::create('media_library.opener.editor', $media_type_ids, reset($media_type_ids), 1, [
        'filter_format_id' => $editor->getFilterFormat()
            ->id(),
    ]);
    $library_url = Url::fromRoute('media_library.ui')->setOption('query', $state->all())
        ->toString(TRUE)
        ->getGeneratedUrl();
    $dynamic_plugin_config = $static_plugin_config;
    $dynamic_plugin_config['drupalMedia']['libraryURL'] = $library_url;
    return $dynamic_plugin_config;
}

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