addDisplay example

/** * Tests the display test plugin. * * @see \Drupal\views_test_data\Plugin\views\display\DisplayTest */
  public function testDisplayPlugin() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container->get('renderer');
    $view = Views::getView('test_view');

    // Add a new 'display_test' display and test it's there.     $view->storage->addDisplay('display_test');
    $displays = $view->storage->get('display');

    $this->assertTrue(isset($displays['display_test_1']), 'Added display has been assigned to "display_test_1"');

    // Check the display options are like expected.     $options = [
      'display_options' => [],
      'display_plugin' => 'display_test',
      'id' => 'display_test_1',
      'display_title' => 'Display test',
      'position' => 1,
    ];
'#description' => $this->t('Will re-generate the subquery for this relationship every time the view is run, instead of only when these options are saved. Use for testing if you are making changes elsewhere. WARNING: seriously impairs performance.'),
    ];
  }

  /** * Helper function to create a pseudo view. * * We use this to obtain our subquery SQL. */
  protected function getTemporaryView() {
    $view = View::create(['base_table' => $this->definition['base']]);
    $view->addDisplay('default');
    return $view->getExecutable();
  }

  /** * When the form is submitted, make sure to clear the subquery string cache. */
  public function submitOptionsForm(&$form, FormStateInterface $form_state) {
    $cid = 'views_relationship_groupwise_max:' . $this->view->storage->id() . ':' . $this->view->current_display . ':' . $this->options['id'];
    \Drupal::cache('data')->delete($cid);
  }

  

  public function newDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
    $this->initDisplay();

    $id = $this->storage->addDisplay($plugin_id$title$id);
    $this->displayHandlers->addInstanceId($id);

    $display = $this->displayHandlers->get($id);
    $display->newDisplay();
    return $display;
  }

  /** * Gets the current style plugin. * * @return \Drupal\views\Plugin\views\style\StylePluginBase * The current style plugin. */
$config->set('cache.page.max_age', 3600);
    $config->save();
  }

  /** * Tests that the view route title is translated. */
  public function testViewTitleTranslation() {
    $view = Views::getView('test_view');

    // Create a test display, add path and default language title.     $view->storage->addDisplay('page');
    $displays = $view->storage->get('display');
    $displays['default']['display_options']['title'] = 'Title EN';
    $displays['page_1']['display_options']['path'] = 'test-view';
    $view->storage->set('display', $displays);
    $view->save();
    // We need to rebuild the routes to discover the route to the     // view display.     \Drupal::service('router.builder')->rebuild();

    $admin_user = $this->drupalCreateUser(['translate configuration']);
    $this->drupalLogin($admin_user);

    
$created_loaded = View::load('test_view_storage_new');
    $this->assertSame($created->uuid()$created_loaded->uuid(), 'The created UUID has been saved correctly.');
  }

  /** * Tests adding, saving, and loading displays on configuration entities. */
  protected function displayTests() {
    // Check whether a display can be added and saved to a View.     $view = View::load('test_view_storage_new');

    $new_id = $view->addDisplay('page', 'Test', 'test');
    $display = $view->get('display');

    // Ensure the right display_plugin is created/instantiated.     $this->assertEquals('page', $display[$new_id]['display_plugin'], 'New page display "test" uses the right display plugin.');

    $executable = $view->getExecutable();
    $executable->initDisplay();
    $this->assertInstanceOf(Page::class$executable->displayHandlers->get($new_id));

    // To save this with a new ID, we should use createDuplicate().     $view = $view->createDuplicate();
    
/** * Tests XSS coming from View block labels. */
  protected function doViewTest() {
    // Create a View without a custom label for its block Display. The     // admin_label of the block then becomes just the View's label.     $view = View::create([
      'id' => $this->randomMachineName(),
      'label' => '<script>alert("view1");</script>',
    ]);
    $view->addDisplay('block');
    $view->save();

    // Create a View with a custom label for its block Display. The     // admin_label of the block then becomes the View's label combined with     // the Display's label.     $view = View::create([
      'id' => $this->randomMachineName(),
      'label' => '<script>alert("view2");</script>',
    ]);
    $view->addDisplay('block', 'Fish & chips');
    $view->save();

    
->with($view_executable)
      ->willReturn(TRUE);

    $style_manager->expects($this->once())
      ->method('createInstance')
      ->willReturn($style_plugin);

    $this->routes = new RouteCollection();
    $this->routes->add('test_1', new Route('/test/1'));
    $this->routes->add('view.test_view.page_1', new Route('/test/2'));

    $view->addDisplay('page', NULL, 'page_1');
  }

  /** * Tests if adding a requirement to a route only modify one route. */
  public function testRoutesRequirements() {
    $this->restExport->collectRoutes($this->routes);

    $requirements_1 = $this->routes->get('test_1')->getRequirements();
    $requirements_2 = $this->routes->get('view.test_view.page_1')->getRequirements();

    


  /** * Tests display areas. */
  public function testDisplayAreas() {
    // Show the advanced column.     $this->config('views.settings')->set('ui.show.advanced_column', TRUE)->save();

    // Add a new data display to the view.     $view = Views::getView('test_display');
    $view->storage->addDisplay('display_no_area_test');
    $view->save();

    $this->drupalGet('admin/structure/views/view/test_display/edit/display_no_area_test_1');

    $areas = [
      'header',
      'footer',
      'empty',
    ];

    // Assert that the expected text is found in each area category.
/** * {@inheritdoc} */
  public function getTypedData() {
    $this->storage->getTypedData();
  }

  /** * {@inheritdoc} */
  public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
    return $this->storage->addDisplay($plugin_id$title$id);
  }

  /** * {@inheritdoc} */
  public function isInstallable() {
    return $this->storage->isInstallable();
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.