Hot answers tagged

5

For access control on routes, you can write a service which implements AccessInterface. At its simplest, this is just a class placed in a module's src/Access folder with a single method public function access(AccountInterface $account), returning a flavour of AccessResult. Then you simply register your class in the module's services.yml, annotate the route ...


4

Where should I place this complex access control in a way that I can easily call it in several controllers and hooks? Is there a name for the kind of feature I'm going to program? The term/concept you're looking for is a Service: Drupal 8 introduces the concept of services to decouple reusable functionality and makes these services pluggable and ...


1

Not Drupal specific, but you should use the status code 302. Redirects with a status code 301 are cached very aggressively by browsers. In Drupal custom code, never send a response directly, set it in the event, so that it can be returned and cached properly by Drupal, which is by the way not a bad thing, because the page cache can handle different cached ...


1

Alright got it working! The redirect module hooks into the kernel.request event and will redirect if you're doing wildcard routing like I am below. You may want to split this up into two services since we're hooking into two events, but they're directly related so I chose to keep it simple. Basic explanation of methods in here is: PathSubscriber::...


1

Drupal uses both route access and entity access. You need to add your access check in hook_entity_access() because the media entity module is denying create access. Use route access for non entity pages.


Only top voted, non community-wiki answers of a minimum length are eligible