Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drupal 8 snippets for different functionality

Dynamic Permissions

  1. Add a class with public method to return an array of permission(s)
  2. Add to *.permissions.yml
  3. Example:
permission_callbacks:
  - Drupal\field_ui\FieldUiPermissions::fieldPermissions

Dynamic Permissions

  1. Add a class under Routing by extending \Drupal\Core\Routing\RouteSubscriberBase
  2. Add to *.services.yml
  3. Example:
field_ui.subscriber:
    class: Drupal\field_ui\Routing\RouteSubscriber
    arguments: ['@entity.manager']
    tags:
     - { name: event_subscriber }

Access Check

  1. Add a class under Access by extending \Drupal\Core\Routing\Access\AccessInterface
  2. Add to *.services.yml
  3. Example:
  access_check.field_ui.form_mode:
    class: Drupal\field_ui\Access\FormModeAccessCheck
    arguments: ['@entity.manager']
    tags:
     - { name: access_check, applies_to: _field_ui_form_mode_access }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment