class ContactFormAccessControlHandler
Same name and namespace in other branches
- 11.x core/modules/contact/src/ContactFormAccessControlHandler.php \Drupal\contact\ContactFormAccessControlHandler
- 10 core/modules/contact/src/ContactFormAccessControlHandler.php \Drupal\contact\ContactFormAccessControlHandler
- 8.9.x core/modules/contact/src/ContactFormAccessControlHandler.php \Drupal\contact\ContactFormAccessControlHandler
Defines the access control handler for the contact form entity type.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Entity\EntityAccessControlHandler implements \Drupal\Core\Entity\EntityAccessControlHandlerInterface extends \Drupal\Core\Entity\EntityHandlerBase
- class \Drupal\contact\ContactFormAccessControlHandler extends \Drupal\Core\Entity\EntityAccessControlHandler
- class \Drupal\Core\Entity\EntityAccessControlHandler implements \Drupal\Core\Entity\EntityAccessControlHandlerInterface extends \Drupal\Core\Entity\EntityHandlerBase
Expanded class hierarchy of ContactFormAccessControlHandler
See also
\Drupal\contact\Entity\ContactForm.
File
-
core/
modules/ contact/ src/ ContactFormAccessControlHandler.php, line 15
Namespace
Drupal\contactView source
class ContactFormAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
if ($operation == 'view') {
// Do not allow access personal form via site-wide route.
return AccessResult::allowedIfHasPermission($account, 'access site-wide contact form')->andIf(AccessResult::allowedIf($entity->id() !== 'personal'));
}
elseif ($operation == 'delete' || $operation == 'update') {
// Do not allow the 'personal' form to be deleted, as it's used for
// the personal contact form.
return AccessResult::allowedIfHasPermission($account, 'administer contact forms')->andIf(AccessResult::allowedIf($entity->id() !== 'personal'));
}
return parent::checkAccess($entity, $operation, $account);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.