function SmartDefaultSettings::getCandidates
Same name in other branches
- 10 core/modules/ckeditor5/src/SmartDefaultSettings.php \Drupal\ckeditor5\SmartDefaultSettings::getCandidates()
- 11.x core/modules/ckeditor5/src/SmartDefaultSettings.php \Drupal\ckeditor5\SmartDefaultSettings::getCandidates()
Finds candidates for the still needed restrictions among disabled plugins.
Parameters
\Drupal\ckeditor5\HTMLRestrictions $provided: The already provided HTML restrictions, thanks to already enabled CKEditor 5 plugins.
\Drupal\ckeditor5\HTMLRestrictions $still_needed: The still needed HTML restrictions, unmet by the already enabled CKEditor 5 plugins.
\Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition[] $disabled_plugin_definitions: The list of not yet enabled CKEditor 5 plugin definitions, amongst which candidates must be found.
Return value
array A nested array with a tree structure covering: 1. tag name 2. concrete attribute name, `-attribute-none-` (meaning no attributes allowed on this tag) or `-attribute-any-` (meaning any attribute allowed on this tag). 3. (optional) attribute value (if concrete attribute name in previous level), `TRUE` or `FALSE` 4. (optional) attribute value restriction 5. candidate CKEditor 5 plugin ID for the HTML elements in the hierarchy and the surplus score as the value. In other words: the leaf of this is always a leaf, and a selected CKEditor 5 plugin ID is always the parent of a leaf.
1 call to SmartDefaultSettings::getCandidates()
- SmartDefaultSettings::addToolbarItemsToMatchHtmlElementsInFormat in core/
modules/ ckeditor5/ src/ SmartDefaultSettings.php - Adds CKEditor 5 toolbar items to match the format's HTML elements.
File
-
core/
modules/ ckeditor5/ src/ SmartDefaultSettings.php, line 633
Class
- SmartDefaultSettings
- Generates CKEditor 5 settings for existing text editors/formats.
Namespace
Drupal\ckeditor5Code
private static function getCandidates(HTMLRestrictions $provided, HTMLRestrictions $still_needed, array $disabled_plugin_definitions) : array {
$plugin_candidates = [];
if (!$still_needed->allowsNothing()) {
foreach ($disabled_plugin_definitions as $definition) {
// Only proceed if the plugin has configured elements and the plugin
// does not have conditions. In the future we could add support for
// automatically enabling filters, but for now we assume that the filter
// configuration cannot be modified.
if (!$definition->hasConditions() && $definition->hasElements()) {
[
$net_new,
$surplus_additions,
] = self::computeNetNewElementsForPlugin($provided, $still_needed, $definition);
if (!$net_new->allowsNothing()) {
$plugin_id = $definition->id();
$creatable_elements = HTMLRestrictions::fromString(implode(' ', $definition->getCreatableElements()));
$surplus_score = static::computeSurplusScore($surplus_additions, $still_needed);
foreach ($net_new->getAllowedElements() as $tag_name => $attributes_config) {
// Non-specific attribute restrictions: `FALSE` or `TRUE`.
// TRICKY: PHP does not support boolean array keys, so map these
// to a string. The string must not be a valid attribute name, so
// use a leading and trailing dash.
if (!is_array($attributes_config)) {
if ($attributes_config === FALSE && !array_key_exists($tag_name, $creatable_elements->getAllowedElements())) {
// If this plugin is not able to create the plain tag, then
// cannot be a candidate for the tag without attributes.
continue;
}
$non_specific_attribute = $attributes_config ? '-attributes-any-' : '-attributes-none-';
$plugin_candidates[$tag_name][$non_specific_attribute][$plugin_id] = $surplus_score;
continue;
}
// With specific attribute restrictions: array.
foreach ($attributes_config as $attribute_name => $attribute_config) {
if (!is_array($attribute_config)) {
$plugin_candidates[$tag_name][$attribute_name][$attribute_config][$plugin_id] = $surplus_score;
}
else {
foreach ($attribute_config as $allowed_attribute_value => $allowed_attribute_value_config) {
$plugin_candidates[$tag_name][$attribute_name][$allowed_attribute_value][$allowed_attribute_value_config][$plugin_id] = $surplus_score;
}
}
}
// If this plugin supports unneeded attributes, it still makes a
// valid candidate for supporting the HTML tag.
$plugin_candidates[$tag_name]['-attributes-none-'][$plugin_id] = $surplus_score;
}
}
}
}
}
return $plugin_candidates;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.