function _filter_url_escape_comments

Same name and namespace in other branches
  1. 10 core/modules/filter/filter.module \_filter_url_escape_comments()
  2. 9 core/modules/filter/filter.module \_filter_url_escape_comments()
  3. 8.9.x core/modules/filter/filter.module \_filter_url_escape_comments()
  4. 7.x modules/filter/filter.module \_filter_url_escape_comments()
  5. main core/modules/filter/filter.module \_filter_url_escape_comments()

Escapes the contents of HTML comments.

Callback for preg_replace_callback() within _filter_url().

Parameters

array $match: An array containing matches to replace from preg_replace_callback(), whereas $match[1] is expected to contain the content to be filtered.

bool|null $escape: (optional) A Boolean indicating whether to escape (TRUE) or unescape comments (FALSE). Defaults to NULL, indicating neither. If TRUE, statically cached $comments are reset.

Deprecated

in drupal:11.4.0 and is removed from drupal:13.0.0. The logic has been split between \Drupal\filter\Plugin\Filter\FilterUrl::escapeComments() and \Drupal\filter\Plugin\Filter\FilterUrl::unescapeComments(), and no replacement is provided.

See also

https://www.drupal.org/node/3566774

Related topics

File

core/modules/filter/filter.module, line 471

Code

function _filter_url_escape_comments($match, $escape = NULL) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. The logic has been split between \\Drupal\\filter\\Plugin\\Filter\\FilterUrl::escapeComments() and \\Drupal\\filter\\Plugin\\Filter\\FilterUrl::unescapeComments(), and no replacement is provided. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  static $mode, $comments = [];
  if (isset($escape)) {
    $mode = $escape;
    if ($escape) {
      $comments = [];
    }
    return;
  }
  // Replace all HTML comments with a '<!-- [hash] -->' placeholder.
  if ($mode) {
    $content = $match[1];
    $hash = hash('sha256', $content);
    $comments[$hash] = $content;
    return "<!-- {$hash} -->";
  }
  else {
    $hash = $match[1];
    $hash = trim($hash);
    $content = $comments[$hash];
    return "<!--{$content}-->";
  }
}

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