You are here

class ViewsBulkOperationsEventSubscriber in Views Bulk Operations (VBO) 8.2

Same name and namespace in other branches
  1. 8.3 src/EventSubscriber/ViewsBulkOperationsEventSubscriber.php \Drupal\views_bulk_operations\EventSubscriber\ViewsBulkOperationsEventSubscriber
  2. 8 src/EventSubscriber/ViewsBulkOperationsEventSubscriber.php \Drupal\views_bulk_operations\EventSubscriber\ViewsBulkOperationsEventSubscriber
  3. 4.0.x src/EventSubscriber/ViewsBulkOperationsEventSubscriber.php \Drupal\views_bulk_operations\EventSubscriber\ViewsBulkOperationsEventSubscriber

Defines module event subscriber class.

Allows getting data of core entity views.

Hierarchy

Expanded class hierarchy of ViewsBulkOperationsEventSubscriber

1 string reference to 'ViewsBulkOperationsEventSubscriber'
views_bulk_operations.services.yml in ./views_bulk_operations.services.yml
views_bulk_operations.services.yml
1 service uses ViewsBulkOperationsEventSubscriber
views_bulk_operations.view_data_provider in ./views_bulk_operations.services.yml
Drupal\views_bulk_operations\EventSubscriber\ViewsBulkOperationsEventSubscriber

File

src/EventSubscriber/ViewsBulkOperationsEventSubscriber.php, line 14

Namespace

Drupal\views_bulk_operations\EventSubscriber
View source
class ViewsBulkOperationsEventSubscriber implements EventSubscriberInterface {

  // Subscribe to the VBO event with high priority
  // to prepopulate the event data.
  const PRIORITY = 999;

  /**
   * Object that gets the current view data.
   *
   * @var \Drupal\views_bulk_operations\ViewsBulkOperationsViewDataInterface
   */
  protected $viewData;

  /**
   * Object constructor.
   *
   * @param \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewDataInterface $viewData
   *   The VBO View Data provider service.
   */
  public function __construct(ViewsBulkOperationsViewDataInterface $viewData) {
    $this->viewData = $viewData;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ViewsBulkOperationsEvent::NAME][] = [
      'provideViewData',
      self::PRIORITY,
    ];
    return $events;
  }

  /**
   * Respond to view data request event.
   *
   * @var \Drupal\views_bulk_operations\ViewsBulkOperationsEvent $event
   *   The event to respond to.
   */
  public function provideViewData(ViewsBulkOperationsEvent $event) {
    $view_data = $event
      ->getViewData();
    if (!empty($view_data['table']['entity type'])) {
      $event
        ->setEntityTypeIds([
        $view_data['table']['entity type'],
      ]);
      $event
        ->setEntityGetter([
        'callable' => [
          $this->viewData,
          'getEntityDefault',
        ],
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsBulkOperationsEventSubscriber::$viewData protected property Object that gets the current view data.
ViewsBulkOperationsEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ViewsBulkOperationsEventSubscriber::PRIORITY constant
ViewsBulkOperationsEventSubscriber::provideViewData public function Respond to view data request event.
ViewsBulkOperationsEventSubscriber::__construct public function Object constructor.