function ContactAccessControlHandler::checkCreateAccess
Separate from the checkAccess because the entity does not yet exist. It will be created during the 'add' process.
Parameters
\Drupal\Core\Session\AccountInterface $account: The user for which to check access.
array $context: An array of key-value pairs to pass additional context when needed.
string|null $entity_bundle: (optional) The bundle of the entity. Required if the entity supports bundles, defaults to NULL otherwise.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides EntityAccessControlHandler::checkCreateAccess
File
-
modules/
content_entity_example/ src/ ContactAccessControlHandler.php, line 47
Class
- ContactAccessControlHandler
- Access controller for the contact entity.
Namespace
Drupal\content_entity_exampleCode
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');
}