I have a view displaying list of latest node revisions.

The view has title field.

The website gives users permissions to access node/{nid}(shows latest revision if published default revision doesn't exist) and node/{nid}/latest (shows latest revision if defaut revision and latest revision is different) depending moderation state and user groups.

I want to override the view's title field according to the rules below:

  • if current user can access node/{nid}/latest the title links to the page
  • else if current user can access node/{nid} the title links to the page
  • else show only title text

Dozens or hundreds of people may simultaneously access the view so I want to keep it fast to display. What is the fastest way to check those?

edit: I searched about hook_node_grants but it only supports view/update/delete operations so I think it can't hold data for node/{nid}/latest. Should I store every pattern in table just like node_access table does and look up on it when view is updated?

  • 2
    Create 3 diff version of your block view. Change the Access for each to permission or user role whatever makes more sense to you. Cache your view, should be already turned on.
    – No Sssweat
    Commented Nov 12, 2019 at 8:34

1 Answer 1


If you know the route name you can check access in PHP. For the second link you can use this route:

\Drupal::service('access_manager')->checkNamedRoute('entity.node.canonical', ['node' => '1'])).

You can find the first one with the help of the Devel module when you click on Current Route Info while displaying the content and look for [_route].

I would put the nid into the title field and override the field content in a preprocess hook. Display the link for each route if the access check returns true. Caching is no problem because caching is by default permission based.

  • It works like a charm! I made a field plugin using the service. Really appreciate your help!
    – 863
    Commented Nov 23, 2019 at 14:40

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.