Ejemplo n.º 1
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);
 }
 /**
  * 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'));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = parent::calculateDependencies();
     $menu = $this->getOption('menu');
     if ($menu['type'] === 'normal' && ($menu_entity = $this->menuStorage->load($menu['menu_name']))) {
         $dependencies[$menu_entity->getConfigDependencyKey()][] = $menu_entity->getConfigDependencyName();
     }
     return $dependencies;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $build = array();
     $build['#markup'] = $this->renderer->executeInRenderContext(new RenderContext(), function () {
         return $this->view->style_plugin->render();
     });
     $this->view->element['#content_type'] = $this->getMimeType();
     $this->view->element['#cache_properties'][] = '#content_type';
     // Encode and wrap the output in a pre tag if this is for a live preview.
     if (!empty($this->view->live_preview)) {
         $build['#prefix'] = '<pre>';
         $build['#plain_text'] = $build['#markup'];
         $build['#suffix'] = '</pre>';
         unset($build['#markup']);
     } elseif ($this->view->getRequest()->getFormat($this->view->element['#content_type']) !== 'html') {
         // This display plugin is primarily for returning non-HTML formats.
         // However, we still invoke the renderer to collect cacheability metadata.
         // Because the renderer is designed for HTML rendering, it filters
         // #markup for XSS unless it is already known to be safe, but that filter
         // only works for HTML. Therefore, we mark the contents as safe to bypass
         // the filter. So long as we are returning this in a non-HTML response
         // (checked above), this is safe, because an XSS attack only works when
         // executed by an HTML agent.
         // @todo Decide how to support non-HTML in the render API in
         //   https://www.drupal.org/node/2501313.
         $build['#markup'] = ViewsRenderPipelineMarkup::create($build['#markup']);
     }
     parent::applyDisplayCachablityMetadata($build);
     return $build;
 }
Ejemplo n.º 5
0
 /**
  * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::submitOptionsForm().
  */
 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::submitOptionsForm($form, $form_state);
     switch ($form_state['section']) {
         case 'title':
             $this->setOption('sitename_title', $form_state['values']['sitename_title']);
             break;
         case 'displays':
             $this->setOption($form_state['section'], $form_state['values'][$form_state['section']]);
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::validate().
  */
 public function validate()
 {
     $errors = parent::validate();
     $menu = $this->getOption('menu');
     if (!empty($menu['type']) && $menu['type'] != 'none' && empty($menu['title'])) {
         $errors[] = $this->t('Display @display is set to use a menu but the menu link text is not set.', array('@display' => $this->display['display_title']));
     }
     if ($menu['type'] == 'default tab') {
         $tab_options = $this->getOption('tab_options');
         if (!empty($tab_options['type']) && $tab_options['type'] != 'none' && empty($tab_options['title'])) {
             $errors[] = $this->t('Display @display is set to use a parent menu but the parent menu link text is not set.', array('@display' => $this->display['display_title']));
         }
     }
     return $errors;
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::submitOptionsForm($form, $form_state);
     $section = $form_state->get('section');
     switch ($section) {
         case 'title':
             $this->setOption('sitename_title', $form_state->getValue('sitename_title'));
             break;
         case 'displays':
             $this->setOption($section, $form_state->getValue($section));
             break;
     }
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     parent::execute();
     $output = $this->view->render();
     return new Response(drupal_render_root($output), 200, array('Content-type' => $this->getMimeType()));
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     parent::execute();
     $output = $this->view->render();
     $header = [];
     $header['Content-type'] = $this->getMimeType();
     $response = new CacheableResponse($this->renderer->renderRoot($output), 200);
     $cache_metadata = CacheableMetadata::createFromRenderArray($output);
     $response->addCacheableDependency($cache_metadata);
     return $response;
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = parent::calculateDependencies();
     $dependencies += ['module' => []];
     $modules = array_map(function ($authentication_provider) {
         return $this->authenticationProviders[$authentication_provider];
     }, $this->getOption('auth'));
     $dependencies['module'] = array_merge($dependencies['module'], $modules);
     return $dependencies;
 }