
| Current Path : /var/www/html/ift/web/core/lib/Drupal/Core/Entity/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/ift/web/core/lib/Drupal/Core/Entity/EntityBundleAccessCheck.php |
<?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;
/**
* Provides an entity bundle checker for the _entity_bundles route requirement.
*/
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) {
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.');
}
}