1

I have Views page with list of enities. The URL is /admin/group/12/members

There is a route in mymodule.routing.yml:

  mymodule_members_list:
  path: '/admin/group/{id}/members'
  requirements:
    _custom_access: '\Drupal\mymodule\Controller\GroupController::access'

The Group entity has field contains group administrator email (field_admin_email)

What I need is to allow administrator to only access a view with group/{id} associated with his email. (I have only problem with views access - it seems like views override my custom access method)

2 Answers 2

5

Solved!

Adding custom access to the Views is very easy: Just create own views access plugin by extending Drupal\views\Plugin\views\access\AccessPluginBase class.

Then implement custom access logic in access method and new rule should appear in PAGE SETTINGS > Access popup window.

1
  • For those who might find this helpful, I was returning TRUE on alterRouteDefinition() (from the custom AccessPluginBase plugin), access was still denied. I fixed the problem by checking some examples on the core and using: $route->setRequirement('_access', 'TRUE') ; on alterRouteDefinition().
    – Pauleau
    Aug 7, 2023 at 14:28
0

Use Views custom permissions module

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.