I have created a view in table format and added a field as global custom text field. I want to show this field to administrator only, not to other created roles. How can I do that?


1 Answer 1


you need to do something like this in global php field :

$uid = 1; 
$user = \Drupal\user\Entity\User::load($uid); 
$roles = $user->getRoles();
if($v == "administrator") 
echo "your-content"; 

Global php field will be available as Replacement pattern add that variable in your custom text field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.