protected function AlinkPostRenderer::extractExistingLinks in Alinks 8
Extract all of the links in an xpath query.
Parameters
string $xpath: An xpath match to parse for links.
Return value
array Unique links from an xpath.
1 call to AlinkPostRenderer::extractExistingLinks()
- AlinkPostRenderer::replace in src/
AlinkPostRenderer.php - Load the content and replace the matched strings with automatic links.
File
- src/
AlinkPostRenderer.php, line 258
Class
- AlinkPostRenderer
- Class AlinkPostRenderer.
Namespace
Drupal\alinksCode
protected function extractExistingLinks($xpath) {
// @TODO: Remove keywords with links which are already in the text
$links = [];
foreach ($xpath
->query('//a') as $link) {
try {
$uri = $this
->normalizeUri($link
->getAttribute('href'));
$links[] = Url::fromUri($uri)
->toString();
} catch (\Exception $exception) {
// Do nothing.
}
}
return array_flip(array_unique($links));
}