protected function configureRoute(\Symfony\Component\Routing\Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) { // defines the controller $route->setDefault('_controller', $class->getName() . '::' . $method->getName()); // verify the other callbacks $options = $annot->getOptions(); foreach ($options as $prop => &$values) { if (!in_array($prop, array('_after_middlewares', '_before_middlewares', '_converters'))) { continue; } if (empty($values)) { continue; } foreach ($values as &$value) { if (is_string($value) && $class->hasMethod($value)) { // call static method from class $value = array($class->getName(), $value); } } unset($value); // clear reference } unset($values); $route->setOptions($options); }
/** * Checks translation access for the entity and operation on the given route. * * @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. * @param string $source * (optional) For a create operation, the language code of the source. * @param string $target * (optional) For a create operation, the language code of the translation. * @param string $language * (optional) For an update or delete operation, the language code of the * translation being updated or deleted. * @param string $entity_type_id * (optional) The entity type ID. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL) { /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */ if ($entity = $route_match->getParameter($entity_type_id)) { if ($account->hasPermission('translate any entity')) { return AccessResult::allowed()->cachePerRole(); } $operation = $route->getRequirement('_access_content_translation_manage'); /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */ $handler = $this->entityManager->getHandler($entity->getEntityTypeId(), 'translation'); // Load translation. $translations = $entity->getTranslationLanguages(); $languages = $this->languageManager->getLanguages(); switch ($operation) { case 'create': $source_language = $this->languageManager->getLanguage($source) ?: $entity->language(); $target_language = $this->languageManager->getLanguage($target) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); $is_new_translation = $source_language->getId() != $target_language->getId() && isset($languages[$source_language->getId()]) && isset($languages[$target_language->getId()]) && !isset($translations[$target_language->getId()]); return AccessResult::allowedIf($is_new_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation)); case 'update': case 'delete': $language = $this->languageManager->getLanguage($language) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); $has_translation = isset($languages[$language->getId()]) && $language->getId() != $entity->getUntranslated()->language()->getId() && isset($translations[$language->getId()]); return AccessResult::allowedIf($has_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation)); } } // No opinion. return AccessResult::neutral(); }
/** * Checks access for the account and route using the custom access checker. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match object to be checked. * @param \Drupal\Core\Session\AccountInterface $account * The account being checked. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) { $callable = $this->controllerResolver->getControllerFromDefinition($route->getRequirement('_custom_access')); $arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match, $account); $arguments = $arguments_resolver->getArguments($callable); return call_user_func_array($callable, $arguments); }
/** * @param Method $method * @param string $endpoint * * @return RpcApiDoc */ protected function processMethod(Method $method, $endpoint) { /** @var string[] $views */ $views = $method->getContext(); if ($method->includeDefaultContext()) { $views[] = 'Default'; } $views[] = 'default'; $request = new Request($method, [], new ParameterBag(['_controller' => $method->getController()])); /** @var array $controller */ $controller = $this->resolver->getController($request); $refl = new \ReflectionMethod($controller[0], $controller[1]); /** @var RpcApiDoc $methodDoc */ $methodDoc = $this->reader->getMethodAnnotation($refl, RpcApiDoc::class); if (null === $methodDoc) { $methodDoc = new RpcApiDoc(['resource' => $endpoint]); } $methodDoc = clone $methodDoc; $methodDoc->setEndpoint($endpoint); $methodDoc->setRpcMethod($method); if (null === $methodDoc->getSection()) { $methodDoc->setSection($endpoint); } foreach ($views as $view) { $methodDoc->addView($view); } $route = new Route($endpoint); $route->setMethods([$endpoint]); $route->setDefault('_controller', get_class($controller[0]) . '::' . $controller[1]); $methodDoc->setRoute($route); return $methodDoc; }
/** * Checks access to create an entity of any bundle for the given route. * * @param \Symfony\Component\Routing\Route $route * The route to check against. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The parameterized 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) { $entity_type_id = $route->getRequirement($this->requirementsKey); $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type_id); // In case there is no "bundle" entity key, check create access with no // bundle specified. if (!$entity_type->hasKey('bundle')) { return $access_control_handler->createAccess(NULL, $account, [], TRUE); } $access = AccessResult::neutral(); $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)); // Include list cache tag as access might change if more bundles are added. if ($entity_type->getBundleEntityType()) { $access->addCacheTags($this->entityTypeManager->getDefinition($entity_type->getBundleEntityType())->getListCacheTags()); // Check if the user is allowed to create new bundles. If so, allow // access, so the add page can show a link to create one. // @see \Drupal\Core\Entity\Controller\EntityController::addPage() $bundle_access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type->getBundleEntityType()); $access = $access->orIf($bundle_access_control_handler->createAccess(NULL, $account, [], TRUE)); if ($access->isAllowed()) { return $access; } } // Check whether an entity of any bundle may be created. foreach ($bundles as $bundle) { $access = $access->orIf($access_control_handler->createAccess($bundle, $account, [], TRUE)); // In case there is a least one bundle user can create entities for, // access is allowed. if ($access->isAllowed()) { break; } } return $access; }
/** * Constructs a Route object. */ public function __construct($name, Route $route, RouteProviderInterface $route_provider) { $this->name = $name; $this->route = $route; $this->routeProvider = $route_provider ? $route_provider : \Drupal::service('router.route_provider'); $this->path = new PathUtility($route->getPath()); }
/** * Build the route for the actual download path. */ protected function getDownloadRoute(EntityTypeInterface $entity_type) { $entity_type_id = $entity_type->id(); $route = new Route("/rdf-export/{$entity_type_id}/{{$entity_type_id}}/{export_format}"); $route->addDefaults(['_controller' => '\\Drupal\\rdf_export\\Controller\\RdfExportController::download', '_title' => 'RDF Export'])->addRequirements(['_permission' => 'export rdf metadata'])->setOption('entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]); return $route; }
public function addCollection($path, array $data = array()) { $route = new Route($path); // $pageClass = ($entity->getResource()->getPageClass()) ? $entity->getResource()->getPageClass() : $entity->getResource()->getPageClass(); $route->setDefaults($data); return $route; }
/** * {@inheritdoc} */ public function access(Route $route, AccountInterface $account, Request $request) { $_entity_revision = $request->attributes->get('_entity_revision'); $operation = $route->getRequirement('_entity_access_revision'); list(, $operation) = explode('.', $operation, 2); return AccessResult::allowedIf($_entity_revision && $this->checkAccess($_entity_revision, $account, $operation))->cachePerPermissions(); }
/** * @covers ::applies */ public function testAppliesWithFormat() { $route_filter = new RequestFormatRouteFilter(); $route = new Route('/test'); $route->setRequirement('_format', 'json'); $this->assertTrue($route_filter->applies($route)); }
public function shouldExcludeRoute($routeName, Route $route) { if ('_' === $routeName[0] || !$route->hasOption('i18n')) { return true; } return false; }
/** * Checks if the user has access to underlying storage for a Panels display. * * @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) { $panels_storage_type = $route_match->getParameter('panels_storage_type'); $panels_storage_id = $route_match->getParameter('panels_storage_id'); $op = $route->getRequirement('_panels_storage_access'); return $this->panelsStorage->access($panels_storage_type, $panels_storage_id, $op, $account); }
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { // description if (null === $annotation->getDescription()) { $comments = explode("\n", $annotation->getDocumentation()); // just set the first line $comment = trim($comments[0]); $comment = preg_replace("#\n+#", ' ', $comment); $comment = preg_replace('#\\s+#', ' ', $comment); $comment = preg_replace('#[_`*]+#', '', $comment); if ('@' !== substr($comment, 0, 1)) { $annotation->setDescription($comment); } } // requirements $requirements = $annotation->getRequirements(); foreach ($route->getRequirements() as $name => $value) { if (!isset($requirements[$name]) && '_method' !== $name && '_scheme' !== $name) { $requirements[$name] = array('requirement' => $value, 'dataType' => '', 'description' => ''); } if ('_scheme' === $name) { $https = 'https' == $value; $annotation->setHttps($https); } } if (method_exists($route, 'getSchemes')) { $annotation->setHttps(in_array('https', $route->getSchemes())); } $paramDocs = array(); foreach (explode("\n", $this->commentExtractor->getDocComment($method)) as $line) { if (preg_match('{^@param (.+)}', trim($line), $matches)) { $paramDocs[] = $matches[1]; } if (preg_match('{^@deprecated\\b(.*)}', trim($line), $matches)) { $annotation->setDeprecated(true); } if (preg_match('{^@link\\b(.*)}', trim($line), $matches)) { $annotation->setLink($matches[1]); } } $regexp = '{(\\w*) *\\$%s\\b *(.*)}i'; foreach ($route->compile()->getVariables() as $var) { $found = false; foreach ($paramDocs as $paramDoc) { if (preg_match(sprintf($regexp, preg_quote($var)), $paramDoc, $matches)) { $requirements[$var]['dataType'] = isset($matches[1]) ? $matches[1] : ''; $requirements[$var]['description'] = $matches[2]; if (!isset($requirements[$var]['requirement'])) { $requirements[$var]['requirement'] = ''; } $found = true; break; } } if (!isset($requirements[$var]) && false === $found) { $requirements[$var] = array('requirement' => '', 'dataType' => '', 'description' => ''); } } $annotation->setRequirements($requirements); }
/** * {@inheritdoc} */ protected function describeRoute(Route $route, array $options = array()) { $requirements = $route->getRequirements(); unset($requirements['_scheme'], $requirements['_method']); // fixme: values were originally written as raw $description = array( '<comment>Path</comment> '.$route->getPath(), '<comment>Host</comment> '.('' !== $route->getHost() ? $route->getHost() : 'ANY'), '<comment>Scheme</comment> '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'), '<comment>Method</comment> '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'), '<comment>Class</comment> '.get_class($route), '<comment>Defaults</comment> '.$this->formatRouterConfig($route->getDefaults()), '<comment>Requirements</comment> '.$this->formatRouterConfig($requirements) ?: 'NO CUSTOM', '<comment>Options</comment> '.$this->formatRouterConfig($route->getOptions()), '<comment>Path-Regex</comment> '.$route->compile()->getRegex(), ); if (isset($options['name'])) { array_unshift($description, '<comment>Name</comment> '.$options['name']); array_unshift($description, $this->formatSection('router', sprintf('Route "%s"', $options['name']))); } if (null !== $route->compile()->getHostRegex()) { $description[] = '<comment>Host-Regex</comment> '.$route->compile()->getHostRegex(); } $this->writeText(implode("\n", $description)."\n", $options); }
public function load($resource, $type = null) { if (true === $this->loaded) { throw new \RuntimeException('Do not add this loader twice'); } $routes = new RouteCollection(); $contextConfigLoader = $this->contextConfigLoader; foreach ($contextConfigLoader->getRouting() as $routing) { foreach ($routing as $id => $info) { if (array_key_exists('pattern', $info)) { $route = new Route($info['pattern']); // merge options and defaults if (array_key_exists('defaults', $info)) { $route->addDefaults($info['defaults']); } if (array_key_exists('options', $info)) { $route->addOptions($info['options']); } if (array_key_exists('requirements', $info)) { $route->addRequirements($info['requirements']); } } $routes->add($id, $route); } } return $routes; }
public function publicToPrivateWriterForward(Route $currentRoute, array $attributes, Request $currentRequest) { $attributes['_controller'] = $this->router->getRouteCollection()->get($currentRoute->getOption('forward_http_route'))->getDefault('_controller'); $subRequest = $currentRequest->duplicate(null, null, $attributes); $response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); return $response; }
/** * {@inheritdoc} */ public function access(Route $route, AccountInterface $account, RdfInterface $rdf_entity, $operation = 'view') { $graph = $route->getOption('graph_name'); $entity_type_id = $route->getOption('entity_type_id'); $storage = $this->entityManager->getStorage($entity_type_id); if (!$storage instanceof RdfEntitySparqlStorage) { throw new \Exception('Storage not supported.'); } // The active graph is the published graph. It is handled by the default // operation handler. // @todo: getActiveGraph is not the default. We should load from settings. $default_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), 'default'); $requested_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), $graph); if ($requested_graph == $default_graph) { return AccessResult::neutral(); } $active_graph_type = $storage->getRequestGraphs($rdf_entity->id()); // Check if there is an entity saved in the passed graph. $storage->setRequestGraphs($rdf_entity->id(), [$graph]); $entity = $storage->load($rdf_entity->id()); // Restore active graph. $storage->setRequestGraphs($rdf_entity->id(), $active_graph_type); // @todo: When the requested graph is the only one and it is not the // default, it is loaded in the default view, so maybe there is no need // to also show a separate tab. return AccessResult::allowedIf($entity && $this->checkAccess($rdf_entity, $route, $account, $operation, $graph))->cachePerPermissions()->addCacheableDependency($rdf_entity); }
/** * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @param mixed $resource * @param null $type * * @return RouteCollection */ public function load($resource, $type = null) : RouteCollection { $resource = (string) $resource; if (in_array($resource, $this->descriptions)) { throw new \RuntimeException("Resource '{$resource}' was already loaded"); } $description = $this->repository->get($resource); $routes = new RouteCollection(); $router = $description->getExtension('router') ?: 'swagger.controller'; $routerController = $description->getExtension('router-controller'); foreach ($description->getPaths() as $pathItem) { $relativePath = ltrim($pathItem->getPath(), '/'); $resourceName = strpos($relativePath, '/') ? substr($relativePath, 0, strpos($relativePath, '/')) : $relativePath; $routerController = $pathItem->getExtension('router-controller') ?: $routerController; foreach ($pathItem->getOperations() as $operation) { $controllerKey = $this->resolveControllerKey($operation, $resourceName, $router, $routerController); $defaults = ['_controller' => $controllerKey, RequestMeta::ATTRIBUTE_URI => $resource, RequestMeta::ATTRIBUTE_PATH => $pathItem->getPath()]; $route = new Route($pathItem->getPath(), $defaults, $this->resolveRequirements($operation)); $route->setMethods($operation->getMethod()); $routes->add($this->createRouteId($resource, $pathItem->getPath(), $controllerKey), $route); } } $this->descriptions[] = $resource; return $routes; }
/** * {@inheritdoc} */ public function getTitle(Request $request, Route $route) { $route_title = NULL; // A dynamic title takes priority. Route::getDefault() returns NULL if the // named default is not set. By testing the value directly, we also avoid // trying to use empty values. if ($callback = $route->getDefault('_title_callback')) { $callable = $this->controllerResolver->getControllerFromDefinition($callback); $arguments = $this->controllerResolver->getArguments($request, $callable); $route_title = call_user_func_array($callable, $arguments); } elseif ($title = $route->getDefault('_title')) { $options = array(); if ($context = $route->getDefault('_title_context')) { $options['context'] = $context; } $args = array(); if ($raw_parameters = $request->attributes->get('_raw_variables')) { foreach ($raw_parameters->all() as $key => $value) { $args['@' . $key] = $value; $args['%' . $key] = $value; } } if ($title_arguments = $route->getDefault('_title_arguments')) { $args = array_merge($args, (array) $title_arguments); } // Fall back to a static string from the route. $route_title = $this->t($title, $args, $options); } return $route_title; }
/** * {@inheritdoc} */ protected function processRoute(Route $route) { // Add entity upcasting information. $parameters = $route->getOption('parameters') ?: array(); $parameters += array('menu_link_plugin' => array('type' => 'menu_link_plugin')); $route->setOption('parameters', $parameters); }
public function createFromRoute(Route $route) { $compiledRoute = $route->compile(); $defaults = array_intersect_key($route->getDefaults(), array_fill_keys($compiledRoute->getVariables(), null)); $tokens = $compiledRoute->getTokens(); return new ExtractedRoute($tokens, $defaults); }
protected function matchCollection($pathinfo, RouteCollection $routes) { foreach ($routes as $name => $route) { $compiledRoute = $route->compile(); if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) { // does it match without any requirements? $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions()); $cr = $r->compile(); if (!preg_match($cr->getRegex(), $pathinfo)) { $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); continue; } foreach ($route->getRequirements() as $n => $regex) { $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions()); $cr = $r->compile(); if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) { $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route); continue 2; } } continue; } // check HTTP method requirement if ($req = $route->getRequirement('_method')) { // HEAD and GET are equivalent as per RFC if ('HEAD' === $method = $this->context->getMethod()) { $method = 'GET'; } if (!in_array($method, $req = explode('|', strtoupper($req)))) { $this->allow = array_merge($this->allow, $req); $this->addTrace(sprintf('Method "%s" does not match the requirement ("%s")', $this->context->getMethod(), implode(', ', $req)), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } } // check HTTP scheme requirement if ($scheme = $route->getRequirement('_scheme')) { if ($this->context->getScheme() !== $scheme) { $this->addTrace(sprintf('Scheme "%s" does not match the requirement ("%s"); the user will be redirected', $this->context->getScheme(), $scheme), self::ROUTE_ALMOST_MATCHES, $name, $route); return true; } } $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route); return true; } }
protected function matchCollection($pathinfo, RouteCollection $routes) { foreach ($routes as $name => $route) { $compiledRoute = $route->compile(); if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) { // does it match without any requirements? $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions()); $cr = $r->compile(); if (!preg_match($cr->getRegex(), $pathinfo)) { $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route); continue; } foreach ($route->getRequirements() as $n => $regex) { $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions()); $cr = $r->compile(); if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) { $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route); continue 2; } } continue; } // check host requirement $hostMatches = array(); if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) { $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } // check HTTP method requirement if ($req = $route->getRequirement('_method')) { // HEAD and GET are equivalent as per RFC if ('HEAD' === ($method = $this->context->getMethod())) { $method = 'GET'; } if (!in_array($method, $req = explode('|', strtoupper($req)))) { $this->allow = array_merge($this->allow, $req); $this->addTrace(sprintf('Method "%s" does not match the requirement ("%s")', $this->context->getMethod(), implode(', ', $req)), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } } // check condition if ($condition = $route->getCondition()) { if (!$this->getExpressionLanguage()->evaluate($condition, array('context' => $this->context, 'request' => $this->request))) { $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $condition), self::ROUTE_ALMOST_MATCHES, $name, $route); continue; } } // check HTTP scheme requirement if ($requiredSchemes = $route->getSchemes()) { $scheme = $this->context->getScheme(); if (!$route->hasScheme($scheme)) { $this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes ("%s"); the user will be redirected to first required scheme', $scheme, implode(', ', $requiredSchemes)), self::ROUTE_ALMOST_MATCHES, $name, $route); return true; } } $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route); return true; } }
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) { if ($annot instanceof BrickRoute) { $route->setDefault('_controller', $annot->getService() . ':' . $method->getName()); } else { $route->setDefault('_controller', $class->getName() . '::' . $method->getName()); } }
/** * {@inheritdoc} */ protected function describeRoute(Route $route, array $options = array()) { $requirements = $route->getRequirements(); unset($requirements['_scheme'], $requirements['_method']); $output = '- Path: ' . $route->getPath() . "\n" . '- Host: ' . ('' !== $route->getHost() ? $route->getHost() : 'ANY') . "\n" . '- Scheme: ' . ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY') . "\n" . '- Method: ' . ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY') . "\n" . '- Class: ' . get_class($route) . "\n" . '- Defaults: ' . $this->formatRouterConfig($route->getDefaults()) . "\n" . '- Requirements: ' . $this->formatRouterConfig($requirements) ?: 'NONE' . "\n" . '- Options: ' . $this->formatRouterConfig($route->getOptions()) . "\n" . '- Path-Regex: ' . $route->compile()->getRegex(); $this->write(isset($options['name']) ? $options['name'] . "\n" . str_repeat('-', strlen($options['name'])) . "\n\n" . $output : $output); $this->write("\n"); }
/** * Checks routing access for the node revision. * * @param \Symfony\Component\Routing\Route $route * The route to check against. * @param \Drupal\Core\Session\AccountInterface $account * The currently logged in account. * @param int $node_revision * (optional) The node revision ID. If not specified, but $node is, access * is checked for that object's revision. * @param \Drupal\node\NodeInterface $node * (optional) A node object. Used for checking access to a node's default * revision when $node_revision is unspecified. Ignored when $node_revision * is specified. If neither $node_revision nor $node are specified, then * access is denied. * * @return string * A \Drupal\Core\Access\AccessInterface constant value. */ public function access(Route $route, AccountInterface $account, $node_revision = NULL, NodeInterface $node = NULL) { if ($node_revision) { $node = $this->nodeStorage->loadRevision($node_revision); } $operation = $route->getRequirement('_access_node_revision'); return $node && $this->checkAccess($node, $account, $operation) ? static::ALLOW : static::DENY; }
/** * Checks routing access for the support_ticket revision. * * @param \Symfony\Component\Routing\Route $route * The route to check against. * @param \Drupal\Core\Session\AccountInterface $account * The currently logged in account. * @param int $support_ticket_revision * (optional) The support_ticket revision ID. If not specified, but * $support_ticket is, access is checked for that object's revision. * @param \Drupal\support_ticket\SupportTicketInterface $support_ticket * (optional) A support_ticket object. Used for checking access to a * support_ticket's default revision when $support_ticket_revision is * unspecified. Ignored when $support_ticket_revision is specified. If neither * $support_ticket_revision nor $support_ticket are specified, then access is * denied. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ public function access(Route $route, AccountInterface $account, $support_ticket_revision = NULL, SupportTicketInterface $support_ticket = NULL) { if ($support_ticket_revision) { $support_ticket = $this->supportTicketStorage->loadRevision($support_ticket_revision); } $operation = $route->getRequirement('_access_support_ticket_revision'); return AccessResult::allowedIf($support_ticket && $this->checkAccess($support_ticket, $account, $operation))->cachePerPermissions(); }
/** * Checks routing access for the node revision. * * @param \Symfony\Component\Routing\Route $route * The route to check against. * @param \Drupal\Core\Session\AccountInterface $account * The currently logged in account. * @param int $node_revision * (optional) The node revision ID. If not specified, but $node is, access * is checked for that object's revision. * @param \Drupal\node\NodeInterface $node * (optional) A node object. Used for checking access to a node's default * revision when $node_revision is unspecified. Ignored when $node_revision * is specified. If neither $node_revision nor $node are specified, then * access is denied. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ public function access(Route $route, AccountInterface $account, $node_revision = NULL, NodeInterface $node = NULL) { if ($node_revision) { $node = $this->nodeStorage->loadRevision($node_revision); } $operation = $route->getRequirement('_access_node_revision'); return AccessResult::allowedIf($node && $this->checkAccess($node, $account, $operation))->cachePerPermissions(); }
/** * {@inheritdoc} */ public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { if (!$route->getOption('old_options')) { return; } $annotation->setDeprecated(true); $annotation->setDocumentation($annotation->getDocumentation() . "\n\nDeprecated since v1.8. Will be removed in v2.0"); }
/** * {@inheritdoc} */ protected function getAttributes(Route $route, $name, array $attributes) { if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) { $name = $route->getRouteKey(); } $attributes[RouteObjectInterface::ROUTE_NAME] = $name; $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route; return $this->mergeDefaults($attributes, $route->getDefaults()); }