You are here

protected static function MultiStepDisplay::trimSingleHtmlTag in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/EntityBrowser/SelectionDisplay/MultiStepDisplay.php \Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay\MultiStepDisplay::trimSingleHtmlTag()

Make HTML with single tag suitable for Ajax response.

Comments will be removed and also whitespace characters, because Ajax JS "insert" command handling checks number of base elements in response and wraps it in a "div" tag if there are more then one base element.

Parameters

string $html: HTML content.

Return value

string Returns cleaner HTML content, suitable for Ajax responses.

1 call to MultiStepDisplay::trimSingleHtmlTag()
MultiStepDisplay::handleAjaxCommand in src/Plugin/EntityBrowser/SelectionDisplay/MultiStepDisplay.php
Handler to generate Ajax response, after command is executed.

File

src/Plugin/EntityBrowser/SelectionDisplay/MultiStepDisplay.php, line 341

Class

MultiStepDisplay
Show current selection and delivers selected entities.

Namespace

Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay

Code

protected static function trimSingleHtmlTag($html) {
  $clearHtml = trim($html);

  // Remove comments around main single HTML tag. RegEx flag 's' is there to
  // allow matching on whitespaces too. That's needed, because generated HTML
  // contains a lot newlines.
  if (preg_match_all('/(<(?!(!--)).+((\\/)|(<\\/[a-z]+))>)/is', $clearHtml, $matches)) {
    if (!empty($matches) && !empty($matches[0])) {
      $clearHtml = $matches[0][0];
    }
  }
  return $clearHtml;
}