class FarmGroupMembersViewsAccessCheck in farmOS 2.x
Checks access for displaying Views of group members.
Hierarchy
- class \Drupal\farm_group\Access\FarmGroupMembersViewsAccessCheck implements AccessInterface
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
File
- modules/
asset/ group/ src/ Access/ FarmGroupMembersViewsAccessCheck.php, line 13
Namespace
Drupal\farm_group\AccessView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FarmGroupMembersViewsAccessCheck:: |
protected | property | The asset storage. | |
FarmGroupMembersViewsAccessCheck:: |
public | function | A custom access check. | |
FarmGroupMembersViewsAccessCheck:: |
public | function | FarmGroupMembersViewsAccessCheck constructor. |