EntityCreateAccessCheck.php in Drupal 8
File
core/lib/Drupal/Core/Entity/EntityCreateAccessCheck.php
View source
<?php
namespace Drupal\Core\Entity;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
class EntityCreateAccessCheck implements AccessInterface {
use DeprecatedServicePropertyTrait;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
protected $entityTypeManager;
protected $requirementsKey = '_entity_create_access';
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
if ($entity_type_manager instanceof EntityManagerInterface) {
@trigger_error('Passing the entity.manager service to EntityCreateAccessCheck::__construct() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Pass the new dependencies instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->entityTypeManager = \Drupal::entityTypeManager();
}
else {
$this->entityTypeManager = $entity_type_manager;
}
$this->entityTypeManager = $entity_type_manager;
}
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
list($entity_type, $bundle) = explode(':', $route
->getRequirement($this->requirementsKey) . ':');
if ($bundle && strpos($bundle, '{') !== FALSE) {
foreach ($route_match
->getRawParameters()
->all() as $name => $value) {
$bundle = str_replace('{' . $name . '}', $value, $bundle);
}
if (strpos($bundle, '{') !== FALSE) {
return AccessResult::neutral(sprintf("Could not find '%s' request argument, therefore cannot check create access.", $bundle));
}
}
return $this->entityTypeManager
->getAccessControlHandler($entity_type)
->createAccess($bundle, $account, [], TRUE);
}
}