- Issue created by @chipchenko
- Status changed to Closed: won't fix
6 months ago 5:43pm 22 May 2024
The username is not shown in the page title for user profile streams.
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();
}
}
Closed: won't fix
12.3
Other