37 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
38 $this->entityTypeManager = $entity_type_manager;
61 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
63 $requirement = $route->getRequirement($this->requirementsKey);
64 $ands = explode(
'+', $requirement);
66 foreach ($ands as $requirement) {
67 $context = static::extractContext($route_match, $requirement);
68 if (empty($context)) {
69 return AccessResult::forbidden();
74 $field_config = $context->getFieldConfig();
76 $entity_type = $field_config->getTargetEntityTypeId();
77 $entity_bundle = $field_config->getTargetBundle();
78 $entity = $context->getEntity();
84 $chain[] = $entity->access(
'edit', $account, TRUE);
87 $chain[] = $this->entityTypeManager->getAccessControlHandler($entity_type)
88 ->createAccess($entity_bundle, $account, [], TRUE);
92 return AccessResult::forbidden();
97 $access = AccessResult::allowed();
98 foreach ($chain as $next_access) {
99 $access = $access->andIf($next_access);
103 $access = AccessResult::neutral();
120 public static function extractContext(RouteMatchInterface $route_match, $requirement) {
121 if (preg_match(
'/\{(.*)\}$/', $requirement, $matches)) {
122 return $route_match->getParameter($matches[1]);
__construct(EntityTypeManagerInterface $entity_type_manager)
static extractContext(RouteMatchInterface $route_match, $requirement)
access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)