You are here

class ViewsBulkOperationsAccess in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 src/Access/ViewsBulkOperationsAccess.php \Drupal\views_bulk_operations\Access\ViewsBulkOperationsAccess
  2. 8.2 src/Access/ViewsBulkOperationsAccess.php \Drupal\views_bulk_operations\Access\ViewsBulkOperationsAccess
  3. 4.0.x src/Access/ViewsBulkOperationsAccess.php \Drupal\views_bulk_operations\Access\ViewsBulkOperationsAccess

Defines module access rules.

Hierarchy

Expanded class hierarchy of ViewsBulkOperationsAccess

1 string reference to 'ViewsBulkOperationsAccess'
views_bulk_operations.services.yml in ./views_bulk_operations.services.yml
views_bulk_operations.services.yml
1 service uses ViewsBulkOperationsAccess
views_bulk_operations.access in ./views_bulk_operations.services.yml
Drupal\views_bulk_operations\Access\ViewsBulkOperationsAccess

File

src/Access/ViewsBulkOperationsAccess.php, line 14

Namespace

Drupal\views_bulk_operations\Access
View source
class ViewsBulkOperationsAccess implements AccessInterface {

  /**
   * Temporary user storage object.
   *
   * @var \Drupal\user\PrivateTempStoreFactory
   */
  protected $tempStoreFactory;

  /**
   * Object constructor.
   */
  public function __construct(PrivateTempStoreFactory $tempStoreFactory) {
    $this->tempStoreFactory = $tempStoreFactory;
  }

  /**
   * A custom access check.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   * @param \Drupal\Core\Routing\RouteMatch $routeMatch
   *   The matched route.
   */
  public function access(AccountInterface $account, RouteMatch $routeMatch) {
    $parameters = $routeMatch
      ->getParameters()
      ->all();
    $tempstore_name = 'views_bulk_operations_' . $parameters['view_id'] . '_' . $parameters['display_id'];
    $view_data = $this->tempStoreFactory
      ->get($tempstore_name)
      ->get($account
      ->id());
    if (!empty($view_data)) {
      return AccessResult::allowed();
    }
    return AccessResult::forbidden();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsBulkOperationsAccess::$tempStoreFactory protected property Temporary user storage object.
ViewsBulkOperationsAccess::access public function A custom access check.
ViewsBulkOperationsAccess::__construct public function Object constructor.