protected function Internal::generateFormatTagsSetting

Builds the "format_tags" configuration part of the CKEditor JS settings.

Parameters

\Drupal\editor\Plugin\Core\Entity\Editor $editor: A configured text editor object.

Return value

array An array containing the "format_tags" configuration.

See also

getConfig()

1 call to Internal::generateFormatTagsSetting()
Internal::getConfig in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/Internal.php
Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getConfig().

File

drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/Internal.php, line 248
Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal.

Class

Internal
Defines the "internal" plugin (i.e. core plugins part of our CKEditor build).

Namespace

Drupal\ckeditor\Plugin\CKEditorPlugin

Code

protected function generateFormatTagsSetting(Editor $editor) {

  // The <p> tag is always allowed — HTML without <p> tags is nonsensical.
  $format_tags = array(
    'p',
  );

  // Given the list of possible format tags, automatically determine whether
  // the current text format allows this tag, and thus whether it should show
  // up in the "Format" dropdown.
  $possible_format_tags = array(
    'h1',
    'h2',
    'h3',
    'h4',
    'h5',
    'h6',
    'pre',
  );
  foreach ($possible_format_tags as $tag) {
    $input = '<' . $tag . '>TEST</' . $tag . '>';
    $output = trim(check_markup($input, $editor->format));
    if ($input == $output) {
      $format_tags[] = $tag;
    }
  }
  return implode(';', $format_tags);
}