Skip to content

Instantly share code, notes, and snippets.

@vijaycs85
Last active June 24, 2020 16:42
Show Gist options
  • Save vijaycs85/7405183c02c7dc979cab84e761107b3c to your computer and use it in GitHub Desktop.
Save vijaycs85/7405183c02c7dc979cab84e761107b3c to your computer and use it in GitHub Desktop.
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