You are here

public function SourceEditing::getElementsSubset in Drupal 10

File

core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/SourceEditing.php, line 70

Class

SourceEditing
CKEditor 5 Source Editing plugin configuration.

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin

Code

public function getElementsSubset() : array {

  // Drupal needs to know which plugin can create a particular <tag>, and not
  // just a particular attribute on a tag: <tag attr>.
  // SourceEditing enables every tag a plugin lists, even if it's only there
  // to add support for an attribute. So, compute a list of only the tags.
  // F.e.: <foo attr>, <bar>, <baz bar> would result in <foo>, <bar>, <baz>.
  $r = HTMLRestrictions::fromString(implode(' ', $this->configuration['allowed_tags']));
  $plain_tags = $r
    ->extractPlainTagsSubset()
    ->toCKEditor5ElementsArray();

  // Return the union of the "tags only" list and the original configuration,
  // but omit duplicates (the entries that were already "tags only").
  // F.e.: merging the tags only list of <foo>, <bar>, <baz> with the original
  // list of <foo attr>, <bar>, <baz bar> would result in <bar> having a
  // duplicate.
  $subset = array_unique(array_merge($plain_tags, $this->configuration['allowed_tags']));
  return $subset;
}