function Heading::enabledHeadingsToTags

Same name and namespace in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Heading.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::enabledHeadingsToTags()
  2. 10 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Heading.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::enabledHeadingsToTags()

Returns an array of enabled tags based on the enabled headings.

Parameters

string[] $enabled_headings: Array of the enabled headings.

Return value

string[] List of tags provided by the enabled headings.

1 call to Heading::enabledHeadingsToTags()
Heading::getElementsSubset in core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Heading.php
Returns a configured subset of the elements supported by this plugin.

File

core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Heading.php, line 203

Class

Heading
CKEditor 5 Heading plugin.

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin

Code

private function enabledHeadingsToTags(array $enabled_headings) : array {
  $plugin_definition = $this->getPluginDefinition();
  $elements = $plugin_definition->getElements();
  $heading_keyed_by_model = [];
  foreach ($plugin_definition->getCKEditor5Config()['heading']['options'] as $configured_heading) {
    if (isset($configured_heading['model'])) {
      $heading_keyed_by_model[$configured_heading['model']] = $configured_heading;
    }
  }
  $tags_to_return = [];
  foreach ($enabled_headings as $model) {
    if (isset($heading_keyed_by_model[$model]) && isset($heading_keyed_by_model[$model]['view'])) {
      $element_as_tag = "<{$heading_keyed_by_model[$model]['view']}>";
      if (in_array($element_as_tag, $elements, TRUE)) {
        $tags_to_return[] = "<{$heading_keyed_by_model[$model]['view']}>";
      }
    }
  }
  return $tags_to_return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.