Username not shown in title on user stream

Created on 16 May 2024, 6 months ago
Updated 22 May 2024, 6 months ago

Problem/Motivation

The username is not shown in the page title for user profile streams.

Steps to reproduce

Go to a user profile stream (example /user/2/stream) and there is no username in the page head title.
The username is show in the title for /user/2/edit .

Is there a way for the username associated with the user profile being looked at to be in the title of the user stream page?

What I have tried so far is a custom module with the below code with no luck.

use Drupal\Core\Routing\RouteMatchInterface;

 function custom_user_title_preprocess_page_title(array &$variables) {
   $route_match = \Drupal::routeMatch();
   $route_name = $route_match->getRouteName();
   // Check if the current route is the user page.
   if ($route_name === 'entity.user.canonical') {
     // Get the user entity from the route parameters.
     $user = $route_match->getParameter('user');
     // Check if the user entity is valid.
     if ($user && $user instanceof \Drupal\user\Entity\User) {
       // Get the username of the user.
       $username = $user->getAccountName();
       // Set the page title to include the username.
       $variables['title'] = $username . ' | ' . $variables['title'];
     }
   }
 }

I have also tried the below with no luck

function socialblue_preprocess_page_title(&$variables) {
  $route_match = \Drupal::routeMatch();
  if ($route_match->getRouteName() === 'entity.profile.canonical') {
    $variables['title'] = $variables['user']->getDisplayName();
  }
}
Feature request
Status

Closed: won't fix

Version

12.3

Component

Other

Created by

🇦🇴Angola chipchenko

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024