EntityBundleAccessCheck.php in Drupal 9
File
core/lib/Drupal/Core/Entity/EntityBundleAccessCheck.php
View source
<?php
namespace Drupal\Core\Entity;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
class EntityBundleAccessCheck implements AccessInterface {
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
@trigger_error('The ' . __NAMESPACE__ . '\\EntityBundleAccessCheck is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Specify the list of bundles in the entity parameter, under "bundle" key, as a sequence, instead. See https://www.drupal.org/node/3155569', E_USER_DEPRECATED);
if ($route
->hasRequirement('_entity_bundles')) {
list($entity_type, $bundle_definition) = explode(':', $route
->getRequirement('_entity_bundles'));
$bundles = explode('|', $bundle_definition);
$parameters = $route_match
->getParameters();
if ($parameters
->has($entity_type)) {
$entity = $parameters
->get($entity_type);
if ($entity instanceof EntityInterface && in_array($entity
->bundle(), $bundles, TRUE)) {
return AccessResult::allowed()
->addCacheableDependency($entity);
}
}
}
return AccessResult::neutral('The entity bundle does not match the route _entity_bundles requirement.');
}
}