Bad DX to create views access plugins

Created on 15 November 2014, almost 10 years ago
Updated 6 February 2024, 7 months ago

Problem/Motivation

Let's create some views access plugin using a custom access function:

class TestAccess extends AccessPluginBase {
  public function access(AccountInterface $account) {
    return $account->id() === 1;
  }

  public function alterRouteDefinition(Route $route) {
    // WTF do you put here, this is quite complex.
    $route->setRequirement('_', ...);
  }
}

Proposed resolution

Boot up the plugin by default by moving the plugin options into the route definition and boot the plugin using
just those information. With that you could actually skip most alterRouteDefinition()calls in access plugins.

Remaining tasks

User interface changes

API changes

πŸ“Œ Task
Status

Active

Version

9.5

Component
ViewsΒ  β†’

Last updated about 14 hours ago

Created by

πŸ‡©πŸ‡ͺGermany dawehner

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tea.time

    ahh!!! Found this issue because I am very confused by the fact that the `access()` method is apparently not called by path-based displays, and thus if you need an access check to use custom logic (i.e. cannot be accomplished by a built-in route requirement like permission or role) - you have to implement not only `access()` but also `alterRouteDefinition()` to attach a custom access callback to the route, which I would want to be the same exact logic as this `access()` method is already doing...? Oh man. I'm sad this issue was posted 9 years ago.

Production build 0.71.5 2024