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];
} /**
* Computes a score for the given surplus compared to the given need.
*
* @param \Drupal\ckeditor5\HTMLRestrictions $surplus
* A surplus compared to what is needed.
* @param \Drupal\ckeditor5\HTMLRestrictions $needed
* Exactly what is needed.
*
* @return int
* A surplus score. Lower is better. Scores are a positive integer.
*
* @see https://www.drupal.org/project/drupal/issues/3231328#comment-14444987
*/