protected function SiteSettingEntityAccessControlHandler::checkCreateAccess in Site Settings and Labels 8
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.
Overrides EntityAccessControlHandler::checkCreateAccess
File
- src/
SiteSettingEntityAccessControlHandler.php, line 82
Class
- SiteSettingEntityAccessControlHandler
- Access controller for the Site Setting entity.
Namespace
Drupal\site_settingsCode
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
// If site setting is not multiple, then creating more is not allowed.
if ($entity_bundle) {
// Get bundle info.
/** @var \Drupal\site_settings\Entity\SiteSettingEntityType $bundle */
$bundle = $this->entityTypeManager
->getStorage($this->entityType
->getBundleEntityType())
->load($entity_bundle);
if (!$bundle->multiple) {
// Get count of settings in the selected bundle.
$count = $this->entityTypeManager
->getStorage('site_setting_entity')
->getQuery('AND')
->condition('type', $entity_bundle)
->count()
->execute();
if ($count) {
return AccessResult::forbidden();
}
}
}
return AccessResult::allowedIfHasPermission($account, 'add site setting entities');
}