Chris@0: entityManager = $entity_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks access to create the entity type and bundle for the given route. Chris@0: * Chris@0: * @param \Symfony\Component\Routing\Route $route Chris@0: * The route to check against. Chris@0: * @param \Drupal\Core\Routing\RouteMatchInterface $route_match Chris@0: * The parametrized route. Chris@0: * @param \Drupal\Core\Session\AccountInterface $account Chris@0: * The currently logged in account. Chris@0: * Chris@0: * @return \Drupal\Core\Access\AccessResultInterface Chris@0: * The access result. Chris@0: */ Chris@0: public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) { Chris@0: list($entity_type, $bundle) = explode(':', $route->getRequirement($this->requirementsKey) . ':'); Chris@0: Chris@0: // The bundle argument can contain request argument placeholders like Chris@0: // {name}, loop over the raw variables and attempt to replace them in the Chris@0: // bundle name. If a placeholder does not exist, it won't get replaced. Chris@0: if ($bundle && strpos($bundle, '{') !== FALSE) { Chris@0: foreach ($route_match->getRawParameters()->all() as $name => $value) { Chris@0: $bundle = str_replace('{' . $name . '}', $value, $bundle); Chris@0: } Chris@0: // If we were unable to replace all placeholders, deny access. Chris@0: if (strpos($bundle, '{') !== FALSE) { Chris@17: return AccessResult::neutral(sprintf("Could not find '%s' request argument, therefore cannot check create access.", $bundle)); Chris@0: } Chris@0: } Chris@0: return $this->entityManager->getAccessControlHandler($entity_type)->createAccess($bundle, $account, [], TRUE); Chris@0: } Chris@0: Chris@0: }