Esempio n. 1
0
 /**
  * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::initDisplay().
  */
 public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL)
 {
     parent::initDisplay($view, $display, $options);
     // Set the default row style. Ideally this would be part of the option
     // definition, but in this case it's dependent on the view's base table,
     // which we don't know until init().
     $row_plugins = Views::fetchPluginNames('row', $this->getType(), array($view->storage->get('base_table')));
     $default_row_plugin = key($row_plugins);
     if (empty($this->options['row']['type'])) {
         $this->options['row']['type'] = $default_row_plugin;
     }
 }
Esempio n. 2
0
 /**
  * Tests the getRouteName method.
  */
 public function testGetRouteName()
 {
     list($view) = $this->setupViewExecutableAccessPlugin();
     $display = array();
     $display['display_plugin'] = 'page';
     $display['id'] = 'page_1';
     $display['display_options'] = array('path' => 'test_route');
     $this->pathPlugin->initDisplay($view, $display);
     $route_name = $this->pathPlugin->getRouteName();
     // Ensure that the expected routename is returned.
     $this->assertEquals('view.test_id.page_1', $route_name);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL)
 {
     parent::initDisplay($view, $display, $options);
     $request_content_type = $this->view->getRequest()->getRequestFormat();
     // Only use the requested content type if it's not 'html'. If it is then
     // default to 'json' to aid debugging.
     // @todo Remove the need for this when we have better content negotiation.
     if ($request_content_type != 'html') {
         $this->setContentType($request_content_type);
     } elseif (!empty($options['style']['options']['formats']) && !isset($options['style']['options']['formats'][$this->getContentType()])) {
         $this->setContentType(reset($options['style']['options']['formats']));
     }
     $this->setMimeType($this->view->getRequest()->getMimeType($this->contentType));
 }
 /**
  * Tests altering routes with optional parameters in the overridden route.
  */
 public function testAlterRoutesWithOptionalParameters()
 {
     $collection = new RouteCollection();
     $collection->add('test_route', new Route('test_route/{parameter}', array('_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController::content')));
     list($view) = $this->setupViewExecutableAccessPlugin();
     $display = array();
     $display['display_plugin'] = 'page';
     $display['id'] = 'page_1';
     $display['display_options'] = array('path' => 'test_route/%');
     $display['display_options']['arguments'] = array('test_id' => array(), 'test_id2' => array());
     $this->pathPlugin->initDisplay($view, $display);
     $view_route_names = $this->pathPlugin->alterRoutes($collection);
     $this->assertEquals(array('test_id.page_1' => 'test_route'), $view_route_names);
     // Ensure that the test_route is overridden.
     $route = $collection->get('test_route');
     $this->assertInstanceOf('\\Symfony\\Component\\Routing\\Route', $route);
     $this->assertEquals('test_id', $route->getDefault('view_id'));
     $this->assertEquals('page_1', $route->getDefault('display_id'));
     // Ensure that the path did not changed and placeholders are respected.
     $this->assertEquals('/test_route/{parameter}/{arg_1}', $route->getPath());
     $this->assertEquals(array('arg_0' => 'parameter'), $route->getOption('_view_argument_map'));
 }
 /**
  * {@inheritdoc}
  */
 public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL)
 {
     parent::initDisplay($view, $display, $options);
     $this->setContentType('json');
     $this->setMimeType($this->view->getRequest()->getMimeType($this->contentType));
 }