You are here

function UrlShortener::_shortener_url_behavior in Shorten URLs 8

Determines the link caption based on the filter behavior setting.

1 call to UrlShortener::_shortener_url_behavior()
UrlShortener::process in modules/shortener/src/Plugin/Filter/UrlShortener.php
{@inheritdocs}

File

modules/shortener/src/Plugin/Filter/UrlShortener.php, line 95
Contains \Drupal\shortener\Plugin\Filter\UrlShortener.

Class

UrlShortener
Provides a filter to limit allowed HTML tags.

Namespace

Drupal\shortener\Plugin\Filter

Code

function _shortener_url_behavior($match, $partial = FALSE, $behavior = NULL, $max_length = NULL) {
  static $_behavior;
  if ($behavior !== NULL) {
    $_behavior = $behavior;
  }
  static $_max_length;
  if ($max_length !== NULL) {
    $_max_length = $max_length;
  }
  if (!empty($match)) {
    $match[2] = \Drupal\Component\Utility\Html::decodeEntities($match[2]);
    $caption = '';
    $href = $match[2];
    $title = check_url($match[2]);
    if ($_behavior == 'short' || $_behavior == 'strict') {
      $caption = shorten_url($match[2]);
      $href = $caption;
    }
    else {
      $caption = \Drupal\Component\Utility\Html::escape(_filter_url_trim($match[2]));
      if ($partial) {
        $href = 'http://' . check_url($match[2]);
      }
      $title = shorten_url($match[2]);
    }
    return $match[1] . '<a href="' . $href . '" title="' . $title . '" class="shortener-length-' . $_max_length . ' shortener-link shortener-' . $_behavior . '">' . $caption . '</a>' . $match[$partial ? 3 : 5];
  }
  return '';
}