function CKEditor5PluginManager::getEnabledDefinitions
Same name in other branches
- 9 core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getEnabledDefinitions()
- 10 core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getEnabledDefinitions()
2 calls to CKEditor5PluginManager::getEnabledDefinitions()
- CKEditor5PluginManager::getCKEditor5PluginConfig in core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5PluginManager.php - CKEditor5PluginManager::getEnabledLibraries in core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5PluginManager.php
File
-
core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5PluginManager.php, line 185
Class
- CKEditor5PluginManager
- Provides a CKEditor 5 plugin manager.
Namespace
Drupal\ckeditor5\PluginCode
public function getEnabledDefinitions(EditorInterface $editor) : array {
$definitions = $this->getDefinitions();
ksort($definitions);
$definitions_with_plugins_condition = [];
foreach ($definitions as $plugin_id => $definition) {
// Remove definition when plugin has conditions and they are not met.
if ($definition->hasConditions()) {
$plugin = $this->getPlugin($plugin_id, $editor);
if ($this->isPluginDisabled($plugin, $editor)) {
unset($definitions[$plugin_id]);
}
else {
// The `plugins` condition can only be evaluated at the end of
// gathering enabled definitions. ::isPluginDisabled() did not yet
// evaluate that condition.
if (array_key_exists('plugins', $definition->getConditions())) {
$definitions_with_plugins_condition[$plugin_id] = $definition;
}
}
}
elseif ($definition->hasToolbarItems()) {
if (empty(array_intersect($editor->getSettings()['toolbar']['items'], array_keys($definition->getToolbarItems())))) {
unset($definitions[$plugin_id]);
}
}
}
// Only enable the arbitrary HTML Support plugin on text formats with no
// HTML restrictions.
// @see https://ckeditor.com/docs/ckeditor5/latest/api/html-support.html
// @see https://github.com/ckeditor/ckeditor5/issues/9856
if ($editor->getFilterFormat()
->getHtmlRestrictions() !== FALSE) {
unset($definitions['ckeditor5_arbitraryHtmlSupport']);
}
// Evaluate `plugins` condition.
foreach ($definitions_with_plugins_condition as $plugin_id => $definition) {
if (!empty(array_diff($definition->getConditions()['plugins'], array_keys($definitions)))) {
unset($definitions[$plugin_id]);
}
}
if (!isset($definitions['ckeditor5_arbitraryHtmlSupport'])) {
$restrictions = new HTMLRestrictions($this->getProvidedElements(array_keys($definitions), $editor, FALSE));
if ($restrictions->getWildcardSubset()
->allowsNothing()) {
// This is only reached if arbitrary HTML is not enabled. If wildcard
// tags (such as $text-container) are present, they need to
// be resolved via the wildcardHtmlSupport plugin.
// @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getCKEditor5PluginConfig()
unset($definitions['ckeditor5_wildcardHtmlSupport']);
}
}
else {
unset($definitions['ckeditor5_wildcardHtmlSupport']);
}
return $definitions;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.