Ejemplo n.º 1
0
 /**
  * Tests the collectRoutes method with a path containing named parameters.
  *
  * @see \Drupal\views\Plugin\views\display\PathPluginBase::collectRoutes()
  */
 public function testCollectRoutesWithNamedParameters()
 {
     /** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
     list($view) = $this->setupViewExecutableAccessPlugin();
     $view->argument = array();
     $view->argument['nid'] = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\argument\\ArgumentPluginBase')->disableOriginalConstructor()->getMock();
     $display = array();
     $display['display_plugin'] = 'page';
     $display['id'] = 'page_1';
     $display['display_options'] = array('path' => 'test_route/%node/example');
     $this->pathPlugin->initDisplay($view, $display);
     $collection = new RouteCollection();
     $result = $this->pathPlugin->collectRoutes($collection);
     $this->assertEquals(array('test_id.page_1' => 'view.test_id.page_1'), $result);
     $route = $collection->get('view.test_id.page_1');
     $this->assertTrue($route instanceof Route);
     $this->assertEquals('/test_route/{node}/example', $route->getPath());
     $this->assertEquals('test_id', $route->getDefault('view_id'));
     $this->assertEquals('page_1', $route->getDefault('display_id'));
     $this->assertEquals(array('arg_0' => 'node'), $route->getOption('_view_argument_map'));
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function collectRoutes(RouteCollection $collection)
 {
     parent::collectRoutes($collection);
     $view_id = $this->view->storage->id();
     $display_id = $this->display['id'];
     if ($route = $collection->get("view.{$view_id}.{$display_id}")) {
         $style_plugin = $this->getPlugin('style');
         // REST exports should only respond to get methods.
         $route->setMethods(['GET']);
         // Format as a string using pipes as a delimiter.
         if ($formats = $style_plugin->getFormats()) {
             // Allow a REST Export View to be returned with an HTML-only accept
             // format. That allows browsers or other non-compliant systems to access
             // the view, as it is unlikely to have a conflicting HTML representation
             // anyway.
             $route->setRequirement('_format', implode('|', $formats + ['html']));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function collectRoutes(RouteCollection $collection)
 {
     parent::collectRoutes($collection);
     $view_id = $this->view->storage->id();
     $display_id = $this->display['id'];
     if ($route = $collection->get("view.{$view_id}.{$display_id}")) {
         $style_plugin = $this->getPlugin('style');
         // REST exports should only respond to get methods.
         $requirements = array('_method' => 'GET');
         // Format as a string using pipes as a delimiter.
         $requirements['_format'] = implode('|', $style_plugin->getFormats());
         // Add the new requirements to the route.
         $route->addRequirements($requirements);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function collectRoutes(RouteCollection $collection)
 {
     parent::collectRoutes($collection);
     $view_id = $this->view->storage->id();
     $display_id = $this->display['id'];
     if ($route = $collection->get("view.{$view_id}.{$display_id}")) {
         $style_plugin = $this->getPlugin('style');
         // REST exports should only respond to get methods.
         $requirements = array('_method' => 'GET');
         // Add the new requirements to the route.
         $route->addRequirements($requirements);
     }
 }