class ContactAccessControlHandler
Same name in other branches
- 3.x modules/content_entity_example/src/ContactAccessControlHandler.php \Drupal\content_entity_example\ContactAccessControlHandler
- 4.0.x modules/content_entity_example/src/ContactAccessControlHandler.php \Drupal\content_entity_example\ContactAccessControlHandler
Access controller for the contact entity.
Hierarchy
- class \Drupal\content_entity_example\ContactAccessControlHandler extends \Drupal\Core\Entity\EntityAccessControlHandler
Expanded class hierarchy of ContactAccessControlHandler
File
-
content_entity_example/
src/ ContactAccessControlHandler.php, line 13
Namespace
Drupal\content_entity_exampleView source
class ContactAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*
* Link the activities to the permissions. checkAccess() is called with the
* $operation as defined in the routing.yml file.
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
// Check the admin_permission as defined in your @ContentEntityType
// annotation.
$admin_permission = $this->entityType
->getAdminPermission();
if ($account->hasPermission($admin_permission)) {
return AccessResult::allowed();
}
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view contact entity');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit contact entity');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete contact entity');
}
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*
* Separate from the checkAccess because the entity does not yet exist. It
* will be created during the 'add' process.
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
// Check the admin_permission as defined in your @ContentEntityType
// annotation.
$admin_permission = $this->entityType
->getAdminPermission();
if ($account->hasPermission($admin_permission)) {
return AccessResult::allowed();
}
return AccessResult::allowedIfHasPermission($account, 'add contact entity');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ContactAccessControlHandler::checkAccess | protected | function | Link the activities to the permissions. checkAccess() is called with the $operation as defined in the routing.yml file. |
ContactAccessControlHandler::checkCreateAccess | protected | function | Separate from the checkAccess because the entity does not yet exist. It will be created during the 'add' process. |