get() public method

Gets a route by name.
public get ( string $name ) : Symfony\Component\Routing\Route
$name string The route name
return Symfony\Component\Routing\Route $route A Route instance
Exemplo n.º 1
0
 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $e
  */
 public function onKernelView(GetResponseForControllerResultEvent $e)
 {
     $queryset = $e->getControllerResult();
     $routeName = $e->getRequest()->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $interface = 'SDispatcher\\Common\\PaginatorInterface';
     $paginatorClass = $route->getOption(RouteOptions::PAGINATOR_CLASS);
     if (!$paginatorClass || !is_subclass_of($paginatorClass, $interface)) {
         return;
     }
     try {
         /* @var \SDispatcher\Common\PaginatorInterface $paginator */
         $paginator = new $paginatorClass();
         if (!$paginator->supports($queryset)) {
             return;
         }
         list($headers, $data) = $paginator->paginate($e->getRequest(), $queryset, 0, $route->getOption(RouteOptions::PAGE_LIMIT), $route->getOption(RouteOptions::PAGINATED_META_CONTAINER_NAME), $route->getOption(RouteOptions::PAGINATED_DATA_CONTAINER_NAME));
     } catch (\Exception $ex) {
         list($headers, $data) = array(array(), array());
     }
     $response = new DataResponse($data);
     $response->headers->add($headers);
     $e->setResponse($response);
 }
Exemplo n.º 2
0
  /**
   * New and improved hook_menu_alter().
   */
  public function alterRoutes(RouteCollection $collection) {
    // admin/structure/taxonomy
    if ($route = $collection->get('entity.taxonomy_vocabulary.collection')) {
      $route->setRequirements(array(
        '_custom_access' => '\taxonomy_access_fix_route_access',
      ));
      $route->setOption('op', 'index');
    }

    // admin/structure/taxonomy/%vocabulary
    if ($route = $collection->get('entity.taxonomy_vocabulary.overview_form')) {
      $route->setRequirements(array(
        '_custom_access' => '\taxonomy_access_fix_route_access',
      ));
      $route->setOption('op', 'list terms');
    }

    // admin/structure/taxonomy/%vocabulary/add
    if ($route = $collection->get('entity.taxonomy_term.add_form')) {
      $route->setRequirements(array(
        '_custom_access' => '\taxonomy_access_fix_route_access',
      ));
      $route->setOption('op', 'add terms');
    }
  }
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
         // Try to get the route from the current collection.
         $link_template = $entity_type->getLinkTemplate('canonical');
         if (strpos($link_template, '/') !== FALSE) {
             $base_path = '/' . $link_template;
         } else {
             if (!($entity_route = $collection->get("entity.{$entity_type_id}.canonical"))) {
                 continue;
             }
             $base_path = $entity_route->getPath();
         }
         // Inherit admin route status from edit route, if exists.
         $is_admin = FALSE;
         $route_name = "entity.{$entity_type_id}.edit_form";
         if ($edit_route = $collection->get($route_name)) {
             $is_admin = (bool) $edit_route->getOption('_admin_route');
         }
         $path = $base_path . '/translations';
         $route = new Route($path, array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::overview', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_overview' => $entity_type_id), array('parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $route_name = "entity.{$entity_type_id}.content_translation_overview";
         $collection->add($route_name, $route);
         $route = new Route($path . '/add/{source}/{target}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::add', 'source' => NULL, 'target' => NULL, '_title' => 'Add', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_manage' => 'create'), array('parameters' => array('source' => array('type' => 'language'), 'target' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_add", $route);
         $route = new Route($path . '/edit/{language}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::edit', 'language' => NULL, '_title' => 'Edit', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'update'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_edit", $route);
         $route = new Route($path . '/delete/{language}', array('_entity_form' => $entity_type_id . '.content_translation_deletion', 'language' => NULL, '_title' => 'Delete', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'delete'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
         $collection->add("entity.{$entity_type_id}.content_translation_delete", $route);
     }
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function getRouteByName($name, $params = [])
 {
     if ($route = $this->routes->get($name)) {
         return $route;
     }
     return null;
 }
 private function getIndexControllerWithSets($cachePath = null)
 {
     $extractor = $this->getExtractor(null, '', $cachePath);
     $extractor->expects($this->any())->method('getRoutes')->will($this->returnCallback(function (array $sets = array()) {
         $routes = new RouteCollection();
         $routesDefinition = array('no_set' => array(), 'set1' => array('set1'), 'set1set2' => array('set1', 'set2'), 'set3' => array('set3'));
         foreach ($routesDefinition as $name => $routeSets) {
             $routes->add($name, new Route('/' . $name, array(), array(), array('expose_sets' => $routeSets)));
         }
         $routesSet1 = new RouteCollection();
         $routesSet1->add('set1', $routes->get('set1'));
         $routesSet1->add('set1set2', $routes->get('set1set2'));
         $routesSet2Set3 = new RouteCollection();
         $routesSet2Set3->add('set1set2', $routes->get('set1set2'));
         $routesSet2Set3->add('set3', $routes->get('set3'));
         if ($sets == array('set1')) {
             return $routesSet1;
         } elseif ($sets == array('set2', 'set3')) {
             return $routesSet2Set3;
         }
         throw new \InvalidArgumentException(sprintf('Theses sets are not configured : %s', join(', ', $sets)));
     }));
     $controller = new Controller($this->getSerializer(), $extractor);
     return $controller;
 }
Exemplo n.º 6
0
 protected function doKernelResponse(Request $request, Response $response)
 {
     if (!$response instanceof DataResponse) {
         return;
     }
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $acceptedFormat = $route->getOption(RouteOptions::ACCEPTED_FORMAT);
     if (!$acceptedFormat) {
         $response->setContent('');
         $response->setStatusCode(406);
     }
     if ($this->encoder->supportsEncoding($acceptedFormat) && $acceptedFormat === 'json') {
         $contentType = $request->getMimeType($acceptedFormat);
         $jsonResponse = new JsonResponse($response->getContent());
         $response->setContent($jsonResponse->getContent());
         $response->headers->set('Content-Type', $contentType);
     } elseif ($this->encoder->supportsEncoding($acceptedFormat)) {
         $contentType = $request->getMimeType($acceptedFormat);
         $content = $this->encoder->encode($response->getContent(), $acceptedFormat);
         $response->setContent($content);
         $response->headers->set('Content-Type', $contentType);
     }
 }
 /**
  * Handler Kernel Controller events
  *
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     $route = $this->routes->get($request->attributes->get('_route'));
     if ($route && $route->hasContent()) {
         $this->populateContent($route, $request);
     }
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection) {
   if ($route = $collection->get('node.revision_revert_confirm')) {
     $route->setDefault('_form', '\Drupal\revision_ui\Form\NodeRevisionRevertForm');
   }
   if ($route = $collection->get('node.revision_revert_translation_confirm')) {
     $route->setDefault('_form', '\Drupal\revision_ui\Form\NodeRevisionRevertTranslationForm');
   }
 }
Exemplo n.º 9
0
 /**
  * Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRoutesByName().
  */
 public function getRoutesByNames($names)
 {
     $routes = array();
     foreach ($names as $name) {
         $routes[] = $this->routes->get($name);
     }
     return $routes;
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
 {
     if (null === ($route = $this->routes->get($name))) {
         throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
     }
     // the Route has a cache of its own and is not recompiled as long as it does not get modified
     $compiledRoute = $route->compile();
     return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens());
 }
Exemplo n.º 11
0
 public function testAddPrefix()
 {
     $collection = new RouteCollection();
     $collection->add('foo', $foo = new Route('/foo'));
     $collection->add('bar', $bar = new Route('/bar'));
     $collection->addPrefix('/admin');
     $this->assertEquals('/admin/foo', $collection->get('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
     $this->assertEquals('/admin/bar', $collection->get('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
 }
Exemplo n.º 12
0
 /**
  * Handler Kernel Response events
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelReponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $route = $this->routes->get($request->attributes->get('_route'));
     if ($route && $route->hasContent() && !$response->headers->has('Last-Modified')) {
         $this->setLastModifiedHeader($route, $request, $response);
     }
 }
Exemplo n.º 13
0
 /**
  * Handler Kernel Response events
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelReponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $route = $this->routes->get($request->attributes->get('_route'));
     if ($route && $route->isMapped()) {
         $url = $request->attributes->get('_canonical');
         $lastModified = new DateTime($response->headers->get('Last-Modified'));
         $this->sitemap->add($url, $lastModified);
     }
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     if ($collection->get('tmgmt.admin_tmgmt')) {
         $route = $collection->get('tmgmt.admin_tmgmt');
         $route->addRequirements(['_permission' => $collection->get('tmgmt.admin_tmgmt')->getRequirement('_permission') . '+administer translation tasks+provide translation services']);
     }
     foreach ($collection->all() as $route) {
         if (strpos($route->getPath(), '/translate') === 0 && $this->configFactory->get('tmgmt_local.settings')->get('use_admin_theme') || strpos($route->getPath(), '/manage-translate') === 0) {
             $route->setOption('_admin_route', TRUE);
         }
     }
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     // Change path '/user/login' to '/login'.
     if ($route = $collection->get('user.login')) {
         $route->setPath('/login');
     }
     // Always deny access to '/user/logout'.
     // Note that the second parameter of setRequirement() is a string.
     if ($route = $collection->get('user.logout')) {
         $route->setRequirement('_access', 'FALSE');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     // Change path '/user/login' to '/login'.
     if ($route = $collection->get('sociallogin.settings_form')) {
         $route->setPath('admin/config/people/userregistration');
         $defaults = $route->getDefaults();
         $defaults['_title'] = "User Registration settings";
         $route->setDefaults($defaults);
     }
     if ($route = $collection->get('advanced.settings_form')) {
         $route->setPath('admin/config/people/userregistration/advanced');
     }
 }
Exemplo n.º 17
0
 /**
  * @param          $route
  * @param Request  $request
  * @param Response $response
  */
 private function handleRoute($route, Request $request, Response $response)
 {
     $theRoute = $this->routeCollection->get($route['_route']);
     $controllerClass = $theRoute->getOption('karmaController');
     $action = $theRoute->getOption('karmaAction');
     $controller = new $controllerClass($this->dispatcher, $request, $response);
     /* @var $controller \ThinFrame\Karma\ViewController\AbstractController */
     unset($route['_route']);
     $this->dispatcher->trigger($controllerActionEvent = new ControllerActionEvent($request, $response, $controller, $action, $route));
     $actionResponse = $controller->trigger($action, $controllerActionEvent->getArguments());
     $this->dispatcher->trigger($controllerResponseEvent = new ControllerResponseEvent($request, $response, $controller, $action, $controllerActionEvent->getArguments(), $actionResponse));
     $response->setContent((string) $controllerResponseEvent->getActionResponse());
 }
Exemplo n.º 18
0
 /**
  * @param FactoryInterface $factory
  * @param array            $options
  *
  * @return ItemInterface
  */
 public function mainMenu(FactoryInterface $factory, array $options)
 {
     $menu = $factory->createItem('root', array('childrenAttributes' => array('class' => 'sidebar-menu')));
     $menu->addChild('Home', array('route' => 'home', 'label' => sprintf('<i class="fa fa-dashboard"></i> <span>%s</span></a>', $this->translator->trans('menu.dashboard', array(), $this->translationDomain)), 'extras' => array('safe_label' => true), 'attributes' => array('class' => 'treeview')));
     $menu->addChild('Profile', array('uri' => '#', 'label' => sprintf('<i class="fa fa-user"></i> <span>%s</span><i class="fa fa-angle-double-left pull-right"></i></a>', $this->translator->trans('menu.profile', array(), $this->translationDomain)), 'extras' => array('safe_label' => true), 'attributes' => array('class' => 'treeview')));
     $menu['Profile']->setChildrenAttribute('class', 'treeview-menu');
     $menu['Profile']->addChild('UserProfile', array('label' => $this->translator->trans('menu.profile', array(), $this->translationDomain), 'route' => 'symfonian_indonesia_admin_profile_profile', 'attributes' => array('class' => 'treeview')));
     $menu['Profile']->addChild('ChangePassword', array('label' => $this->translator->trans('menu.user.change_password', array(), $this->translationDomain), 'route' => 'symfonian_indonesia_admin_profile_changepassword', 'attributes' => array('class' => 'treeview')));
     if ($this->routeCollection->get('symfonian_indonesia_admin_security_user_new') && $this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
         $this->addUserMenu($menu);
     }
     return $menu;
 }
 /**
  * Tests that removeRoute() removes routes when the module is not enabled.
  *
  * @dataProvider providerTestRemoveRoute
  * @covers ::onAlterRoutes
  *
  * @param string $route_name
  *   The machine name for the route.
  * @param array $requirements
  *   An array of requirements to use for the route.
  * @param bool $removed
  *   Whether or not the route is expected to be removed from the collection.
  */
 public function testRemoveRoute($route_name, array $requirements, $removed)
 {
     $collection = new RouteCollection();
     $route = new Route('', array(), $requirements);
     $collection->add($route_name, $route);
     $event = new RouteBuildEvent($collection, 'test');
     $route_subscriber = new ModuleRouteSubscriber($this->moduleHandler);
     $route_subscriber->onAlterRoutes($event);
     if ($removed) {
         $this->assertNull($collection->get($route_name));
     } else {
         $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $collection->get($route_name));
     }
 }
Exemplo n.º 20
0
 protected function doKernelRequest(Request $request)
 {
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $format = $request->getFormat($request->headers->get('Content-Type', null, true));
     if ($this->decoderProvider->supports($format)) {
         /** @var \FOS\Rest\Decoder\DecoderInterface $decoder */
         $decoder = $this->decoderProvider->getDecoder($format);
         $data = $decoder->decode($request->getContent());
         $request->request->replace(is_array($data) ? $data : array());
     }
 }
Exemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 protected function doKernelRequest(Request $request)
 {
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return null;
     }
     $controller = $request->attributes->get('_controller');
     if (is_string($controller) && class_exists($controller)) {
         $options = $this->resolveControllerOptions($controller);
         $routeName = $request->attributes->get('_route');
         $route = $this->routes->get($routeName);
         $route->addOptions($options);
     }
     return null;
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     $route = $collection->get('user.admin_permissions');
     if ($route) {
         $route->setDefaults(array('_title' => 'Permissions', '_controller' => '\\Drupal\\fpa\\Controller\\FPAController::permissionsList'));
     }
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     // Alter the canonical node route to our custom route
     if ($route = $collection->get('entity.node.canonical')) {
         $route->setDefault('_controller', '\\Drupal\\ahs_discussions\\Controller\\NodeRedirectController::view');
     }
 }
Exemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 protected function alterRoutes(RouteCollection $collection)
 {
     if ($route = $collection->get('system.modules_list')) {
         $route->setDefault('_form', 'Drupal\\mmu\\Form\\ModulesListForm');
         $collection->add('system.modules_list', $route);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alterRoutes(RouteCollection $collection)
 {
     // Replace the content from node.revision_overview route with content
     // generated by revisionOverview method from NodeRevisionController class.
     $route = $collection->get('entity.node.version_history');
     $route->addDefaults(array('_controller' => '\\Drupal\\diff\\Controller\\NodeRevisionController::revisionOverview'));
 }
Exemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function getBaseRoute()
 {
     if ($this->routeCollection) {
         return $this->routeCollection->get($this->getBaseRouteName());
     } else {
         return $this->routeProvider->getRouteByName($this->getBaseRouteName());
     }
 }
Exemplo n.º 27
0
 /**
  * Get the URL to a named route.
  *
  * @param  string  $name
  * @param  array   $parameters
  * @param  bool    $absolute
  * @return string
  */
 public function route($name, $parameters = array(), $absolute = true)
 {
     $route = $this->routes->get($name);
     if (isset($route) and $this->usingQuickParameters($parameters)) {
         $parameters = $this->buildParameterList($route, $parameters);
     }
     return $this->generator->generate($name, $parameters, $absolute);
 }
Exemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 protected function doKernelRequest(Request $request)
 {
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return null;
     }
     if (!$request->attributes->has('_format')) {
         $request->attributes->set('_format', $request->query->get('format'));
     }
     $acceptableFormats = (array) $route->getOption(RouteOptions::SUPPORTED_FORMATS);
     $bestFormat = $this->formatNegotiator->getBestFormat($request, $acceptableFormats, true);
     if (!$bestFormat) {
         return new Response('', 406);
     }
     $route->setOption(RouteOptions::ACCEPTED_FORMAT, $bestFormat);
     return null;
 }
Exemplo n.º 29
0
 /**
  * {@inheritDoc}
  */
 public function generate($name, $parameters = array(), $absolute = false)
 {
     if (null === ($route = $this->routes->get($name))) {
         throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
     }
     // the Route has a cache of its own and is not recompiled as long as it does not get modified
     $compiledRoute = $route->compile();
     return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $absolute, $compiledRoute->getHostnameTokens());
 }
Exemplo n.º 30
0
 /**
  * Build a kernel for a specific route
  *
  * Using StackedHttpKernel factory for better reusability
  *
  * @param array $routeParameters Parameters of the route
  *
  * @return \Stack\StackedHttpKernel
  */
 protected function getStack($routeParameters)
 {
     $route = $this->routeCollection->get($routeParameters['_route']);
     $dispatch = $route->getOption('dispatch');
     $services = array();
     $parameters = array();
     $factory = new StackedHttpKernel($this->container, $dispatch);
     list($name, $stack) = $factory->register(null, 'pyrite.root_kernel', $dispatch);
     return $stack;
 }