You are here

protected static function MailFormatHelper::htmlToMailUrls in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Mail/MailFormatHelper.php \Drupal\Core\Mail\MailFormatHelper::htmlToMailUrls()

Keeps track of URLs and replaces them with placeholder tokens.

Callback for preg_replace_callback() within \Drupal\Core\Mail\MailFormatHelper::htmlToText().

1 call to MailFormatHelper::htmlToMailUrls()
MailFormatHelper::htmlToText in core/lib/Drupal/Core/Mail/MailFormatHelper.php
Transforms an HTML string into plain text, preserving its structure.

File

core/lib/Drupal/Core/Mail/MailFormatHelper.php, line 333

Class

MailFormatHelper
Defines a class containing utility methods for formatting mail messages.

Namespace

Drupal\Core\Mail

Code

protected static function htmlToMailUrls($match = NULL, $reset = FALSE) {

  // @todo Use request context instead.
  global $base_url, $base_path;
  if ($reset) {

    // Reset internal URL list.
    static::$urls = [];
  }
  else {
    if (empty(static::$regexp)) {
      static::$regexp = '@^' . preg_quote($base_path, '@') . '@';
    }
    if ($match) {
      list(, , $url, $label) = $match;

      // Ensure all URLs are absolute.
      static::$urls[] = strpos($url, '://') ? $url : preg_replace(static::$regexp, $base_url . '/', $url);
      return $label . ' [' . count(static::$urls) . ']';
    }
  }
  return static::$urls;
}