You are here

public static function WebformHtmlEditor::checkMarkup in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformHtmlEditor.php \Drupal\webform\Element\WebformHtmlEditor::checkMarkup()

Runs HTML markup through (optional) text format.

Parameters

string $text: The text to be filtered.

array $options: HTML markup options.

Return value

array Render array containing 'processed_text'.

See also

\Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::getMessage

22 calls to WebformHtmlEditor::checkMarkup()
ActionWebformHandler::executeAction in src/Plugin/WebformHandler/ActionWebformHandler.php
Execute this action.
ActionWebformHandler::getSummary in src/Plugin/WebformHandler/ActionWebformHandler.php
Returns a render array summarizing the configuration of the webform handler.
OverrideWebformVariant::debug in src/Plugin/WebformVariant/OverrideWebformVariant.php
Display debugging information.
Webform::buildAccessDenied in src/Element/Webform.php
Build access denied message for a webform.
WebformAccessGroupListBuilder::buildRow in modules/webform_access/src/WebformAccessGroupListBuilder.php
Builds a row for an entity in the entity listing.

... See full list

File

src/Element/WebformHtmlEditor.php, line 236

Class

WebformHtmlEditor
Provides a webform element for entering HTML using CodeMirror, TextFormat, or custom CKEditor.

Namespace

Drupal\webform\Element

Code

public static function checkMarkup($text, array $options = []) {
  $options += [
    'tidy' => \Drupal::config('webform.settings')
      ->get('html_editor.tidy'),
  ];

  // Remove <p> tags around a single line of text, which creates minor
  // margin issues.
  if ($options['tidy']) {
    if (substr_count($text, '<p>') === 1 && preg_match('#^\\s*<p>.*</p>\\s*$#m', $text)) {
      $text = preg_replace('#^\\s*<p>#', '', $text);
      $text = preg_replace('#</p>\\s*$#', '', $text);
    }
  }
  if ($format = \Drupal::config('webform.settings')
    ->get('html_editor.element_format')) {
    return [
      '#type' => 'processed_text',
      '#text' => $text,
      '#format' => $format,
    ];
  }
  else {
    return [
      '#theme' => 'webform_html_editor_markup',
      '#markup' => $text,
      '#allowed_tags' => static::getAllowedTags(),
    ];
  }
}