function SmartDefaultSettings::computeNetNewElementsForPlugin
Same name in other branches
- 10 core/modules/ckeditor5/src/SmartDefaultSettings.php \Drupal\ckeditor5\SmartDefaultSettings::computeNetNewElementsForPlugin()
- 11.x core/modules/ckeditor5/src/SmartDefaultSettings.php \Drupal\ckeditor5\SmartDefaultSettings::computeNetNewElementsForPlugin()
Computes net new needed elements when considering adding the given plugin.
Parameters
\Drupal\ckeditor5\HTMLRestrictions $baseline: The set of HTML restrictions already supported.
\Drupal\ckeditor5\HTMLRestrictions $needed: The set of HTML restrictions that are needed, that is: in addition to $baseline.
\Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition $added_plugin: The CKEditor 5 plugin that is being evaluated to check if it would meet some of the needs.
Return value
array An array containing two values:
- a set of HTML restrictions that indicates the net new additions that are needed
- a set of HTML restrictions that indicates the surplus additions (these are elements that were not needed, but are added by this plugin)
2 calls to SmartDefaultSettings::computeNetNewElementsForPlugin()
- SmartDefaultSettings::addToolbarItemsToMatchHtmlElementsInFormat in core/
modules/ ckeditor5/ src/ SmartDefaultSettings.php - Adds CKEditor 5 toolbar items to match the format's HTML elements.
- SmartDefaultSettings::getCandidates in core/
modules/ ckeditor5/ src/ SmartDefaultSettings.php - Finds candidates for the still needed restrictions among disabled plugins.
File
-
core/
modules/ ckeditor5/ src/ SmartDefaultSettings.php, line 525
Class
- SmartDefaultSettings
- Generates CKEditor 5 settings for existing text editors/formats.
Namespace
Drupal\ckeditor5Code
private static function computeNetNewElementsForPlugin(HTMLRestrictions $baseline, HTMLRestrictions $needed, CKEditor5PluginDefinition $added_plugin) : array {
$plugin_support = HTMLRestrictions::fromString(implode(' ', $added_plugin->getElements()));
// Do not inspect just $plugin_support, but the union of that with the
// already supported elements: wildcard restrictions will only resolve
// if the concrete tags they support are also present.
$potential_future = $baseline->merge($plugin_support);
// This is the heart of the operation: intersect the potential future
// with what we need to achieve, then subtract what is already
// supported. This yields the net new elements.
$net_new = $potential_future->intersect($needed)
->diff($baseline);
// But … we may compute too many.
$surplus_additions = $potential_future->diff($needed)
->diff($baseline);
return [
$net_new,
$surplus_additions,
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.