function EditorManager::getAttachments
Same name and namespace in other branches
- 9 core/modules/editor/src/Plugin/EditorManager.php \Drupal\editor\Plugin\EditorManager::getAttachments()
- 8.9.x core/modules/editor/src/Plugin/EditorManager.php \Drupal\editor\Plugin\EditorManager::getAttachments()
- 10 core/modules/editor/src/Plugin/EditorManager.php \Drupal\editor\Plugin\EditorManager::getAttachments()
Retrieves text editor libraries and JavaScript settings.
Parameters
array $format_ids: An array of format IDs as returned by array_keys(filter_formats()).
Return value
array An array of attachments, for use with #attached.
See also
\Drupal\Core\Render\AttachmentsResponseProcessorInterface::processAttachments()
File
-
core/
modules/ editor/ src/ Plugin/ EditorManager.php, line 70
Class
- EditorManager
- Configurable text editor manager.
Namespace
Drupal\editor\PluginCode
public function getAttachments(array $format_ids) {
$settings = $this->attachments['drupalSettings'] ?? [];
if ($editor_ids_to_load = array_diff($format_ids, array_keys($this->editors))) {
$editors = $this->entityTypeManager
->getStorage('editor')
->loadMultiple($editor_ids_to_load);
// Statically cache the editors and include NULL entries for formats that
// do not have editors.
$this->editors += $editors + array_fill_keys($editor_ids_to_load, NULL);
foreach ($editors as $format_id => $editor) {
$plugin = $this->createInstance($editor->getEditor());
$plugin_definition = $plugin->getPluginDefinition();
// Libraries.
$this->attachments['library'] = array_merge($this->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($this->attachments['library']) && empty($settings)) {
return [];
}
$this->attachments['drupalSettings'] = $settings;
return $this->attachments;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.