class EntityBundleAccessCheck
Provides an entity bundle checker for the _entity_bundles route requirement.
@todo 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.
Hierarchy
- class \Drupal\Core\Entity\EntityBundleAccessCheck implements \Drupal\Core\Routing\Access\AccessInterface
 
Expanded class hierarchy of EntityBundleAccessCheck
See also
https://www.drupal.org/node/3155569
1 file declares its use of EntityBundleAccessCheck
- EntityBundleAccessCheckTest.php in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityBundleAccessCheckTest.php  
1 string reference to 'EntityBundleAccessCheck'
- core.services.yml in core/
core.services.yml  - core/core.services.yml
 
1 service uses EntityBundleAccessCheck
File
- 
              core/
lib/ Drupal/ Core/ Entity/ EntityBundleAccessCheck.php, line 20  
Namespace
Drupal\Core\EntityView source
class EntityBundleAccessCheck implements AccessInterface {
  
  /**
   * Checks entity bundle match based on the _entity_bundles route requirement.
   *
   * @code
   * example.route:
   *   path: foo/{example_entity_type}/{other_parameter}
   *   requirements:
   *     _entity_bundles: 'example_entity_type:example_bundle|other_example_bundle'
   * @endcode
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The parametrized route.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  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')) {
      [$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.');
  }
}
Members
| Title Sort descending | Modifiers | Object type | Summary | 
|---|---|---|---|
| EntityBundleAccessCheck::access | public | function | Checks entity bundle match based on the _entity_bundles route requirement. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.