Convert user ID to user display name for blog views

This commit is contained in:
benjamin melançon 2019-10-03 20:50:40 -04:00
parent 1f9714463f
commit 6306d84c6d

View file

@ -0,0 +1,18 @@
<?php
/**
* Preprocess functions for GEO site.
*/
function geofresco_preprocess_page_title(&$variables) {
// WE SHALL BE SHAMELESS.
$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()])
];
}
}
}