geo-coop/web/themes/custom/geofresco/geofresco.theme
benjamin melançon 6aafa4dfe8 Output permalink URLs to allow remix of date as permalink
Ref https://gitlab.com/drutopia/drutopia/issues/283

This will move into Octavia or even Bulma theme ideally
2020-02-05 14:11:10 -05:00

43 lines
1.2 KiB
Text

<?php
/**
* Preprocess functions for GEO site.
*/
/**
* Implements hook_preprocess_page_title();
*
* @param $variables
*/
function geofresco_preprocess_page_title(&$variables) {
// WE SHALL BE SHAMELESS.
if (!isset($variables['title']) || !is_array($variables['title'])) {
// The pages we're interested in have title as markup, so bail if it's not.
return;
}
$string = isset($variables['title']['#markup']) ? $variables['title']['#markup'] : FALSE;
if ($string && $pos = strpos($string, "'s blog", -7)) {
$uid = substr($string, 0, $pos);
if (is_numeric($uid) && $account = \Drupal\user\Entity\User::load($uid)) {
$variables['title'] = [
'#markup' => t("@username's blog",
['@username' => $account->getDisplayName()])
];
}
}
}
/**
* Implements hook_preprocess_HOOK() for comment.
*
* Shortens and stacks username and submitted date.
*/
function geofresco_preprocess_comment(array &$variables) {
$comment = $variables['elements']['#comment'];
if (isset($comment->in_preview)) {
$variables['permalink_url'] = new Url('<front>');
}
else {
$variables['permalink_url'] = $comment->permalink();
}
}