2020-05-09 21:31:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2021-05-22 13:21:05 +00:00
|
|
|
* Custom blog code.
|
2020-05-09 21:31:34 +00:00
|
|
|
*/
|
|
|
|
|
2021-05-22 13:21:05 +00:00
|
|
|
use Drupal\Core\Url;
|
|
|
|
use Drupal\node\NodeInterface;
|
2020-05-09 21:31:34 +00:00
|
|
|
|
2021-05-22 13:21:05 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_node_links_alter().
|
|
|
|
*/
|
|
|
|
function opdavies_blog_node_links_alter(array &$links, NodeInterface $node): void {
|
|
|
|
if (!method_exists($node, 'getExternalLink')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($link = $node->getExternalLink()) {
|
|
|
|
$links['node']['#links']['node-readmore']['url'] = Url::fromUri($link['uri']);
|
|
|
|
$links['node']['#links']['node-readmore']['title'] = t('Read more<span class="visually-hidden"> about @title</span> (<span class="visually-hidden">on </span>@domain)', [
|
|
|
|
'@domain' => $link['title'],
|
|
|
|
'@title' => $node->label(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 21:31:34 +00:00
|
|
|
|
2021-05-22 13:21:05 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_HOOK().
|
|
|
|
*/
|
|
|
|
function opdavies_blog_preprocess_block(array &$variables): void {
|
|
|
|
// Add the 'markup' class to blocks.
|
|
|
|
if (in_array($variables['plugin_id'], ['views_block:featured_blog_posts-block_1'])) {
|
|
|
|
$variables['attributes']['class'][] = 'markup';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_HOOK().
|
|
|
|
*/
|
|
|
|
function opdavies_blog_preprocess_node(array &$variables): void {
|
|
|
|
if (!method_exists($variables['node'], 'getExternalLink')) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-21 12:18:40 +00:00
|
|
|
|
2021-05-22 13:21:05 +00:00
|
|
|
if ($link = $variables['node']->getExternalLink()) {
|
|
|
|
$variables['url'] = $link['uri'];
|
|
|
|
}
|
2020-05-21 12:18:40 +00:00
|
|
|
}
|