You are here

class ActionsPermissionsEventSubscriber in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 modules/actions_permissions/src/EventSubscriber/ActionsPermissionsEventSubscriber.php \Drupal\actions_permissions\EventSubscriber\ActionsPermissionsEventSubscriber
  2. 8.2 modules/actions_permissions/src/EventSubscriber/ActionsPermissionsEventSubscriber.php \Drupal\actions_permissions\EventSubscriber\ActionsPermissionsEventSubscriber
  3. 4.0.x modules/actions_permissions/src/EventSubscriber/ActionsPermissionsEventSubscriber.php \Drupal\actions_permissions\EventSubscriber\ActionsPermissionsEventSubscriber

Defines module event subscriber class.

Alters actions to make use of permissions created by the module.

Hierarchy

Expanded class hierarchy of ActionsPermissionsEventSubscriber

1 string reference to 'ActionsPermissionsEventSubscriber'
actions_permissions.services.yml in modules/actions_permissions/actions_permissions.services.yml
modules/actions_permissions/actions_permissions.services.yml
1 service uses ActionsPermissionsEventSubscriber
actions_permissions.views_bulk_operations_actions in modules/actions_permissions/actions_permissions.services.yml
Drupal\actions_permissions\EventSubscriber\ActionsPermissionsEventSubscriber

File

modules/actions_permissions/src/EventSubscriber/ActionsPermissionsEventSubscriber.php, line 14

Namespace

Drupal\actions_permissions\EventSubscriber
View source
class ActionsPermissionsEventSubscriber implements EventSubscriberInterface {

  // Subscribe to the VBO event with low priority
  // to let other modules alter requirements first.
  const PRIORITY = -999;

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ViewsBulkOperationsActionManager::ALTER_ACTIONS_EVENT][] = [
      'alterActions',
      static::PRIORITY,
    ];
    return $events;
  }

  /**
   * Alter the actions' definitions.
   *
   * @var \Symfony\Component\EventDispatcher\Event $event
   *   The event to respond to.
   */
  public function alterActions(Event $event) {

    // Don't alter definitions if this is invoked by the
    // own permissions creating method.
    if (!empty($event->alterParameters['skip_actions_permissions'])) {
      return;
    }
    foreach ($event->definitions as $action_id => $definition) {

      // Only process actions that don't define their own requirements.
      if (empty($definition['requirements'])) {
        $permission_id = 'execute ' . $definition['id'];
        if (empty($definition['type'])) {
          $permission_id .= ' all';
        }
        else {
          $permission_id .= ' ' . $definition['type'];
        }
        $definition['requirements']['_permission'] = $permission_id;
        $event->definitions[$action_id] = $definition;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActionsPermissionsEventSubscriber::alterActions public function Alter the actions' definitions.
ActionsPermissionsEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ActionsPermissionsEventSubscriber::PRIORITY constant