You are here

public function FarmGroupMembersViewsAccessCheck::access in farmOS 2.x

A custom access check.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

File

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

Class

FarmGroupMembersViewsAccessCheck
Checks access for displaying Views of group members.

Namespace

Drupal\farm_group\Access

Code

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;
}