You are here

public function InlineLinkExtractor::listAttribute in Printer and PDF versions for Drupal 8+ 8

Same name and namespace in other branches
  1. 2.x src/LinkExtractor/InlineLinkExtractor.php \Drupal\printable\LinkExtractor\InlineLinkExtractor::listAttribute()

List the links at the bottom of page.

Parameters

string $content: The HTML string which has links present.

Return value

string The HTML string, containing links.

Overrides LinkExtractorInterface::listAttribute

File

src/LinkExtractor/InlineLinkExtractor.php, line 76

Class

InlineLinkExtractor
Link extractor.

Namespace

Drupal\printable\LinkExtractor

Code

public function listAttribute($content) {
  $this->crawler
    ->addContent($content);
  $this->links = [];
  $this->crawler
    ->filter('a')
    ->each(function (HtmlPageCrawler $anchor, $uri) {
    global $base_url;
    $href = $anchor
      ->attr('href');
    try {
      $this->links[] = $base_url . $this->aliasMnager
        ->getAliasByPath($href);
    } catch (\Exception $e) {
      $this->links[] = $this
        ->urlFromHref($href)
        ->toString();
    }
  });
  $this->crawler
    ->remove();
  return implode(',', $this->links);
}