Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Working on #2571235: [regression] Roles should depend on objects that are building the granted permissions I realized that callbacks that provides permissions are not necessary part of a class implementing a dedicated interface. If we want to provide also dependencies along with permissions (see #2571235: [regression] Roles should depend on objects that are building the granted permissions) it would be nice to create some laws on how dynamic permissions are provided.
Proposed resolution
- Add a new interface for classes providing dynamic permissions:
interface DynamicPermissionsInterface { public function getPermissions(); public function calculateDependencies(); }
.
- In *.permissions.yml specify the class, instead of the callback.
- Rework
\Drupal\user\PermissionHandler::buildPermissionsYaml()
to enforce the usage of classes implementing the new interface and use the ->getPermissions() method instead of the previously callback. - Provide dependencies and handle them to keep the system integrity.
Remaining tasks
New interface DynamicPermissionsInterface
.
Comments
Comment #2
claudiu.cristea