EditorManager.php in Drupal 8
File
core/modules/editor/src/Plugin/EditorManager.php
View source
<?php
namespace Drupal\editor\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
class EditorManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Editor', $namespaces, $module_handler, 'Drupal\\editor\\Plugin\\EditorPluginInterface', 'Drupal\\editor\\Annotation\\Editor');
$this
->alterInfo('editor_info');
$this
->setCacheBackend($cache_backend, 'editor_plugins');
}
public function listOptions() {
$options = [];
foreach ($this
->getDefinitions() as $key => $definition) {
$options[$key] = $definition['label'];
}
return $options;
}
public function getAttachments(array $format_ids) {
$attachments = [
'library' => [],
];
$settings = [];
foreach ($format_ids as $format_id) {
$editor = editor_load($format_id);
if (!$editor) {
continue;
}
$plugin = $this
->createInstance($editor
->getEditor());
$plugin_definition = $plugin
->getPluginDefinition();
$attachments['library'] = array_merge($attachments['library'], $plugin
->getLibraries($editor));
$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'],
];
}
$this->moduleHandler
->alter('editor_js_settings', $settings);
if (empty($attachments['library']) && empty($settings)) {
return [];
}
$attachments['drupalSettings'] = $settings;
return $attachments;
}
}