class DrupalMediaLibrary in Drupal 8
Same name and namespace in other branches
- 9 core/modules/media_library/src/Plugin/CKEditorPlugin/DrupalMediaLibrary.php \Drupal\media_library\Plugin\CKEditorPlugin\DrupalMediaLibrary
Defines the "drupalmedialibrary" plugin.
@CKEditorPlugin( id = "drupalmedialibrary", label = @Translation("Embed media from the Media Library"), )
@internal Plugin classes are internal.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\media_library\Plugin\CKEditorPlugin\DrupalMediaLibrary implements ContainerFactoryPluginInterface
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DrupalMediaLibrary
3 string references to 'DrupalMediaLibrary'
- editor.editor.basic_html.yml in core/
profiles/ demo_umami/ config/ install/ editor.editor.basic_html.yml - core/profiles/demo_umami/config/install/editor.editor.basic_html.yml
- editor.editor.full_html.yml in core/
profiles/ demo_umami/ config/ install/ editor.editor.full_html.yml - core/profiles/demo_umami/config/install/editor.editor.full_html.yml
- media_library_filter_format_edit_form_validate in core/
modules/ media_library/ media_library.module - Validate callback to ensure the DrupalMediaLibrary button can work correctly.
File
- core/
modules/ media_library/ src/ Plugin/ CKEditorPlugin/ DrupalMediaLibrary.php, line 26
Namespace
Drupal\media_library\Plugin\CKEditorPluginView source
class DrupalMediaLibrary extends CKEditorPluginBase implements ContainerFactoryPluginInterface {
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;
/**
* The media type entity storage.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
*/
protected $mediaTypeStorage;
/**
* Constructs a new DrupalMediaLibrary plugin object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module
* The module extension list.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ModuleExtensionList $extension_list_module, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleExtensionList = $extension_list_module;
$this->mediaTypeStorage = $entity_type_manager
->getStorage('media_type');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('extension.list.module'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function isInternal() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getDependencies(Editor $editor) {
return [
'drupalmedia',
];
}
/**
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
return [
'editor/drupal.editor.dialog',
];
}
/**
* {@inheritdoc}
*/
public function getFile() {
return $this->moduleExtensionList
->getPath('media_library') . '/js/plugins/drupalmedialibrary/plugin.js';
}
/**
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
// If the editor has not been saved yet, we may not be able to create a
// coherent MediaLibraryState object, which is needed in order to generate
// the required configuration. But, if we're creating a new editor, we don't
// need to do that anyway, so just return an empty array.
if ($editor
->isNew()) {
return [];
}
$media_type_ids = $this->mediaTypeStorage
->getQuery()
->execute();
if ($editor
->hasAssociatedFilterFormat()) {
if ($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)) {
// Due to a bug where the active item styling and the focus styling
// create the visual appearance of two active items, we'll move
// the 'image' media type to first position, so that the focused item and
// the active item are the same.
// 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(),
]);
return [
'DrupalMediaLibrary_url' => Url::fromRoute('media_library.ui')
->setOption('query', $state
->all())
->toString(TRUE)
->getGeneratedUrl(),
'DrupalMediaLibrary_dialogOptions' => MediaLibraryUiBuilder::dialogOptions(),
];
}
/**
* {@inheritdoc}
*/
public function getButtons() {
return [
'DrupalMediaLibrary' => [
'label' => $this
->t('Insert from Media Library'),
'image' => $this->moduleExtensionList
->getPath('media_library') . '/js/plugins/drupalmedialibrary/icons/drupalmedialibrary.png',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DrupalMediaLibrary:: |
protected | property | The media type entity storage. | |
DrupalMediaLibrary:: |
protected | property | The module extension list. | |
DrupalMediaLibrary:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
DrupalMediaLibrary:: |
public | function |
Returns the buttons that this plugin provides, along with metadata. Overrides CKEditorPluginButtonsInterface:: |
|
DrupalMediaLibrary:: |
public | function |
Returns the additions to CKEDITOR.config for a specific CKEditor instance. Overrides CKEditorPluginInterface:: |
|
DrupalMediaLibrary:: |
public | function |
Returns a list of plugins this plugin requires. Overrides CKEditorPluginBase:: |
|
DrupalMediaLibrary:: |
public | function |
Returns the Drupal root-relative file path to the plugin JavaScript file. Overrides CKEditorPluginInterface:: |
|
DrupalMediaLibrary:: |
public | function |
Returns a list of libraries this plugin requires. Overrides CKEditorPluginBase:: |
|
DrupalMediaLibrary:: |
public | function |
Indicates if this plugin is part of the optimized CKEditor build. Overrides CKEditorPluginBase:: |
|
DrupalMediaLibrary:: |
public | function |
Constructs a new DrupalMediaLibrary plugin object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |