As it stands template_preprocess_username() uses only user_access('access user profiles') to determine whether the current user can view a profile. However that also includes their own profile which (at least in D7 where this error also occurs) should always be visible.
There's a simple quick fix which involves just adding a check to see if the current user is the same as the username we want.
global $user;
$variables['profile_access'] = user_access('access user profiles') || $account->id() == $user->id();
The equivalent fix works in D7.
Comment | File | Size | Author |
---|---|---|---|
#1 | 2106589-preprocess-username-own-profile.patch | 569 bytes | adaddinsane |
Comments
Comment #1
adaddinsaneAnd here's the patch.
Comment #4
dpiComment #5
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedI don't see how this is a duplicate - that issue is about access to the username, whereas this issue is about displaying a link to the profile page.
Essentially what this issue is saying is that the code which determines whether or not to link to the user profile should match (or at least more closely match) the code in https://api.drupal.org/api/drupal/core%21modules%21user%21src%21UserAcce... which determines whether or not the current user has access to view the profile.
Comment #7
dpiYou're right, I had the wrong issue :). Was supposed to be #1101958: Username template cannot always link to current user
Comment #8
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedOh, yeah, this does look like a duplicate of that one.