Skip to main content
Home
Drupal life hacks

Main navigation

  • Drupal
  • React
  • WP
  • Contact
  • About
User account menu
  • Log in

Breadcrumb

  1. Home

Configuring a Custom Permission Provider Service in Drupal 9/10 Modules

By admin, 7 November, 2024

This is a YAML configuration for a service, likely in a file like my_module.services.yml, which defines services in the my_module Drupal module.

Here's a breakdown:

1. my_permission_provider — This is the name of the service you’re creating to provide custom permissions.

2. class: Drupal\my_module\MyPermissions — This specifies the class implementing the permission logic. Here, it uses the MyPermissions class within the Drupal\my_module namespace.

3. autowire: true — This enables autowiring, which means that dependencies required by this class will be automatically injected by the container.

4. tags — Tags allow you to connect this functionality to the user permissions system in Drupal.
  - name: 'user.permission_provider' — This registers the service as a permission provider for the user system.
  - method: 'myPermissions' — Specifies the method in the MyPermissions class to be used for providing permissions.
  - provider: 'my_module' — Indicates that these permissions are provided by the my_module module.

5. Drupal\my_module\MyPermissions: '@my_permission_provider' — This is an alias, letting you refer to the my_permission_provider service by its class, Drupal\my_module\MyPermissions.

Tags

  • #Drupal Planet
  • Add new comment

Comments2

About text formats

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

BH (not verified)

1 year 5 months ago

site title

The word "Hacks" in your title does not need an apostrophe as it is just a plural (apple --> singular ... apples --> plural); an apostrophe indicates possession ("those are John's things").

  • Reply

admin

11 months 2 weeks ago

In reply to site title by BH (not verified)

THX

THX

  • Reply
Powered by Drupal