public function CclService::prepareLink in Custom Contextual Links 8.2
Prepare a link for injection by running token replacement and access check.
Parameters
array $link: The cached link object.
null|\Drupal\node\Entity\Node $node: The node to sue for token replacement.
Return value
array|bool If access is granted returns a link to be added to contextual links.
File
- src/
CclService.php, line 85
Class
- CclService
- Class CclService.
Namespace
Drupal\cclCode
public function prepareLink(array $link, $node = NULL) {
$title = $node ? $this->token
->replace($link['title'], [
'node' => $node,
]) : $this->token
->replace($link['title']);
$url = $node ? $this->token
->replace($link['url'], [
'node' => $node,
]) : $this->token
->replace($link['url']);
if ($link['urlOptions']['query']) {
$query = $node ? $this->token
->replace($link['urlOptions']['query'], [
'node' => $node,
]) : $this->token
->replace($link['urlOptions']['query']);
parse_str($query, $link['urlOptions']['query']);
}
$processedUrl = Url::fromUri($url, $link['urlOptions']);
$processedLink = [
'title' => $title,
'url' => $processedUrl,
'attributes' => $link['attributes'],
];
return $processedUrl
->access() ? $processedLink : FALSE;
}