Change the title of a View to show a name based on its numeric contextual filter

This is how NOT to do it.

/**
 * 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()])
      ];
    }
  }
}

The approach in the answer here is what we’re doing, the path having the username is handled with an alias. But that doesn’t solve autocreating aliases (which we still need to solve) and it doesn’t solve the title of the view.

Just realizing that the html_page_title will still be wrong… will fix that later, and this abomination of a function will also be gone


https://www.webwash.net/custom-tab-user-profile-page-views-drupal-8/

https://www.drupal.org/forum/general/general-discussion/2008-03-02/how-to-display-users-articles-list-nodes-on-users

https://www.drupal.org/project/drupal/issues/2904908

https://www.drupal.org/project/issues/views_url_alias?categories=All

https://envisioninteractive.com/drupal/using-the-pathauto-api-drupal-module-a-simple-example/

https://www.deeson.co.uk/labs/dynamic-patterns-pathauto