public function FarmLocationAssetViewsAccessCheck::access in farmOS 2.x
A custom access check.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
File
- modules/
core/ ui/ views/ src/ Access/ FarmLocationAssetViewsAccessCheck.php, line 49
Class
- FarmLocationAssetViewsAccessCheck
- Checks access for displaying Views of assets in a location.
Namespace
Drupal\farm_ui_views\AccessCode
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 location.
/** @var \Drupal\asset\Entity\AssetInterface $asset */
$asset = $this->assetStorage
->load($asset_id);
$access = AccessResult::allowedIf($this->assetLocation
->isLocation($asset));
// Invalidate the access result when assets are changed.
$access
->addCacheTags([
"asset_list",
]);
return $access;
}