/** * Tests the generate method with passing in a route object into generate(). * * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException */ public function testGenerateByRoute() { $this->generator = new ProviderBasedGenerator($this->provider); // Setup a route with a numeric parameter, but pass in a string, so it // fails and getRouteDebugMessage should be triggered. $route = new Route('/test'); $route->setPath('/test/{number}'); $route->setRequirement('number', '\\+d'); $this->generator->setStrictRequirements(true); $context = new RequestContext(); $this->generator->setContext($context); $this->assertSame(null, $this->generator->generate($route, array('number' => 'string'))); }
/** * Constructs a new generator object. * * @param \Drupal\Core\Routing\RouteProviderInterface $provider * The route provider to be searched for routes. * @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor * The path processor to convert the system path to one suitable for urls. * @param \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface $route_processor * The route processor. * @param \Drupal\Core\Config\ConfigFactoryInterface $config * The config factory. * @param \Psr\Log\LoggerInterface $logger * An optional logger for recording errors. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * A request stack object. */ public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, ConfigFactoryInterface $config, LoggerInterface $logger = NULL, RequestStack $request_stack) { parent::__construct($provider, $logger); $this->pathProcessor = $path_processor; $this->routeProcessor = $route_processor; $allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https'); UrlHelper::setAllowedProtocols($allowed_protocols); $this->requestStack = $request_stack; }
/** * {@inheritDoc} */ public function getRouteDebugMessage($name, array $parameters = array()) { if (empty($name) && isset($parameters['content_id'])) { return 'Content id ' . $parameters['content_id']; } if ($name instanceof RouteReferrersReadInterface) { return 'Route aware content ' . parent::getRouteDebugMessage($name, $parameters); } return parent::getRouteDebugMessage($name, $parameters); }
/** * Constructs a new generator object. * * @param \Drupal\Core\Routing\RouteProviderInterface $provider * The route provider to be searched for routes. * @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor * The path processor to convert the system path to one suitable for urls. * @param \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface $route_processor * The route processor. * @param \Drupal\Core\Config\ConfigFactoryInterface $config * The config factory. * @param \Drupal\Core\Site\Settings $settings * The read only settings. * @param \Psr\Log\LoggerInterface $logger * An optional logger for recording errors. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * A request stack object. */ public function __construct(RouteProviderInterface $provider, OutboundPathProcessorInterface $path_processor, OutboundRouteProcessorInterface $route_processor, ConfigFactoryInterface $config, Settings $settings, LoggerInterface $logger = NULL, RequestStack $request_stack) { parent::__construct($provider, $logger); $this->pathProcessor = $path_processor; $this->routeProcessor = $route_processor; $this->mixedModeSessions = $settings->get('mixed_mode_sessions', FALSE); $allowed_protocols = $config->get('system.filter')->get('protocols') ?: array('http', 'https'); UrlHelper::setAllowedProtocols($allowed_protocols); $this->requestStack = $request_stack; $this->updateFromRequest(); }