You are here

class FarmGroupMembersViewsAccessCheck in farmOS 2.x

Checks access for displaying Views of group members.

Hierarchy

Expanded class hierarchy of FarmGroupMembersViewsAccessCheck

1 string reference to 'FarmGroupMembersViewsAccessCheck'
farm_group.services.yml in modules/asset/group/farm_group.services.yml
modules/asset/group/farm_group.services.yml
1 service uses FarmGroupMembersViewsAccessCheck
farm_group.group_members_access in modules/asset/group/farm_group.services.yml
Drupal\farm_group\Access\FarmGroupMembersViewsAccessCheck

File

modules/asset/group/src/Access/FarmGroupMembersViewsAccessCheck.php, line 13

Namespace

Drupal\farm_group\Access
View source
class FarmGroupMembersViewsAccessCheck implements AccessInterface {

  /**
   * The asset storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $assetStorage;

  /**
   * FarmGroupMembersViewsAccessCheck constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->assetStorage = $entity_type_manager
      ->getStorage('asset');
  }

  /**
   * A custom access check.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match.
   */
  public function access(RouteMatchInterface $route_match) {

    // If there is no "asset" parameter, bail.
    $asset_id = $route_match
      ->getParameter('asset');
    if (empty($asset_id)) {
      return AccessResult::allowed();
    }

    // Allow access if the asset is a group.

    /** @var \Drupal\asset\Entity\AssetInterface $asset */
    $asset = $this->assetStorage
      ->load($asset_id);
    $access = AccessResult::allowedIf($asset
      ->bundle() == 'group');

    // Invalidate the access result when assets are changed.
    $access
      ->addCacheTags([
      "asset_list",
    ]);
    return $access;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FarmGroupMembersViewsAccessCheck::$assetStorage protected property The asset storage.
FarmGroupMembersViewsAccessCheck::access public function A custom access check.
FarmGroupMembersViewsAccessCheck::__construct public function FarmGroupMembersViewsAccessCheck constructor.