protected function OrganizationAccessControlHandler::checkCreateAccess in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_contact/src/OrganizationAccessControlHandler.php \Drupal\crm_core_contact\OrganizationAccessControlHandler::checkCreateAccess()
- 8.2 modules/crm_core_contact/src/OrganizationAccessControlHandler.php \Drupal\crm_core_contact\OrganizationAccessControlHandler::checkCreateAccess()
Performs create access checks.
This method is supposed to be overwritten by extending classes that do their own custom access checking.
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/
crm_core_contact/ src/ OrganizationAccessControlHandler.php, line 53
Class
- OrganizationAccessControlHandler
- Access control handler for CRM Core Organization entities.
Namespace
Drupal\crm_core_contactCode
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
$organization_type_is_active = empty($entity_bundle);
// Load the organization type entity.
if (!empty($entity_bundle)) {
/* @var \Drupal\crm_core_contact\Entity\ContactType $contact_type_entity */
$organization_type_entity = OrganizationType::load($entity_bundle);
$organization_type_is_active = $organization_type_entity
->status();
}
return AccessResult::allowedIf($organization_type_is_active)
->andIf(AccessResult::allowedIfHasPermissions($account, [
'administer crm_core_organization entities',
'create crm_core_organization entities',
'create crm_core_organization entities of bundle ' . $entity_bundle,
], 'OR'));
}