newDisplay example


  public function DgetDisplay($display_id) {
    return $this->display[$display_id];
  }

  /** * {@inheritdoc} */
  public function duplicateDisplayAsType($old_display_id$new_display_type) {
    $executable = $this->getExecutable();
    $display = $executable->newDisplay($new_display_type);
    $new_display_id = $display->display['id'];
    $displays = $this->get('display');

    // Let the display title be generated by the addDisplay method and set the     // right display plugin, but keep the rest from the original display.     $display_duplicate = $displays[$old_display_id];
    unset($display_duplicate['display_title']);
    unset($display_duplicate['display_plugin']);
    unset($display_duplicate['new_id']);

    $displays[$new_display_id] = NestedArray::mergeDeep($displays[$new_display_id]$display_duplicate);
    
$resultset = [
      [
        'name' => 'Ringo',
      ],
    ];
    $this->assertIdenticalResultset($view$resultset$this->columnMap);
  }

  public function testEqualGroupedExposed() {
    $filters = $this->getGroupedExposedFilters();
    $view = Views::getView('test_view');
    $view->newDisplay('page', 'Page', 'page_1');

    // Filter: Name, Operator: =, Value: Ringo     $filters['name']['group_info']['default_group'] = 1;
    $view->setDisplay('page_1');
    $view->displayHandlers->get('page_1')->overrideOption('filters', $filters);
    $view->save();

    $this->executeView($view);
    $resultset = [
      [
        'name' => 'Ringo',
      ],
// Test the default value of use_more_always.     $view = View::create()->getExecutable();
    $this->assertTrue($view->getDisplay()->getOption('use_more_always'), 'Always display the more link by default.');
  }

  /** * Tests the templates with empty rows. */
  public function testEmptyRow() {
    $view = Views::getView('test_page_display');
    $view->initDisplay();
    $view->newDisplay('page', 'Page', 'empty_row');
    $view->save();

    $styles = [
      'default' => '//div[@class="views-row"]',
      // Olivero does not use the 'views-col' class.       'grid' => '//div[contains(@class, "views-col") or contains(@class, "views-view-grid__item-inner")]',
      'html_list' => '//div[@class="item-list"]//li',
    ];

    $themes = ['olivero', 'stable9', 'stark', 'claro'];

    

  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    $this->installConfig(['system', 'filter']);
    $this->installEntitySchema('user');

    $view = Views::getView('test_view');

    // Add two page displays and a block display.     $page_1 = $view->newDisplay('page', 'Page 1', 'page_1');
    $page_1->setOption('path', 'page_1');
    $page_2 = $view->newDisplay('page', 'Page 2', 'page_2');
    $page_2->setOption('path', 'page_2');
    $view->newDisplay('block', 'Block 1', 'block_1');

    // Add default filter criteria, sort criteria, pager settings and contextual     // filters.     $default = $view->displayHandlers->get('default');
    $default->setOption('filters', [
      'status' => [
        'id' => 'status',
        

        'name' => 'Ringo',
        'age' => 28,
      ],
    ];
    $this->assertIdenticalResultset($view$resultset$this->columnMap);
  }

  public function testFilterNumericExposedGroupedSimple() {
    $filters = $this->getGroupedExposedFilters();
    $view = Views::getView('test_view');
    $view->newDisplay('page', 'Page', 'page_1');

    // Filter: Age, Operator: =, Value: 28     $filters['age']['group_info']['default_group'] = 1;
    $view->setDisplay('page_1');
    $view->displayHandlers->get('page_1')->overrideOption('filters', $filters);
    $view->save();

    $this->executeView($view);
    $resultset = [
      [
        'name' => 'Ringo',
        
$view->setDisplay('page_2');
    $view->initStyle();
    $this->assertInstanceOf(Grid::class$view->style_plugin);
    // @todo Change this rowPlugin type too.     $this->assertInstanceOf(Fields::class$view->rowPlugin);

    // Test the newDisplay() method.     $view = $this->container->get('entity_type.manager')->getStorage('view')->create(['id' => 'test_executable_displays']);
    $executable = $view->getExecutable();

    $executable->newDisplay('page');
    $executable->newDisplay('page');
    $executable->newDisplay('display_test');

    $this->assertInstanceOf(DefaultDisplay::class$executable->displayHandlers->get('default'));
    $this->assertFalse(isset($executable->displayHandlers->get('default')->default_display));
    $this->assertInstanceOf(Page::class$executable->displayHandlers->get('page_1'));
    $this->assertInstanceOf(DefaultDisplay::class$executable->displayHandlers->get('page_1')->default_display);
    $this->assertInstanceOf(Page::class$executable->displayHandlers->get('page_2'));
    $this->assertInstanceOf(DefaultDisplay::class$executable->displayHandlers->get('page_2')->default_display);
    $this->assertInstanceOf(DisplayTest::class$executable->displayHandlers->get('display_test_1'));
    $this->assertInstanceOf(DefaultDisplay::class$executable->displayHandlers->get('display_test_1')->default_display);
  }


  /** * Submit handler to duplicate a display for a view. */
  public function submitDisplayDuplicate($form, FormStateInterface $form_state) {
    $view = $this->entity;
    $display_id = $this->displayID;

    // Create the new display.     $displays = $view->get('display');
    $display = $view->getExecutable()->newDisplay($displays[$display_id]['display_plugin']);
    $new_display_id = $display->display['id'];
    $displays[$new_display_id] = $displays[$display_id];
    $displays[$new_display_id]['id'] = $new_display_id;
    $view->set('display', $displays);

    // By setting the current display the changed marker will appear on the new     // display.     $view->getExecutable()->current_display = $new_display_id;
    $view->cacheSet();

    // Redirect to the new display's edit page.
    $this->assertSession()->responseContains('<p>A paragraph</p>');

    $view = $this->container->get('entity_type.manager')->getStorage('view')->load('test_display_feed');
    $display = &$view->getDisplay('feed_1');
    $display['display_options']['sitename_title'] = 0;
    $view->save();

    $this->drupalGet('test-feed-display.xml');
    $this->assertEquals('test_display_feed', $this->getSession()->getDriver()->getText('//channel/title'));

    // Add a block display and attach the feed.     $view->getExecutable()->newDisplay('block', NULL, 'test');
    $display = &$view->getDisplay('feed_1');
    $display['display_options']['displays']['test'] = 'test';
    $view->save();
    // Test the feed display adds a feed icon to the block display.     $this->drupalPlaceBlock('views_block:test_display_feed-test');
    $this->drupalGet('<front>');
    $feed_icon = $this->cssSelect('div.view-id-test_display_feed a.feed-icon');
    $this->assertStringContainsString('test-feed-display.xml', $feed_icon[0]->getAttribute('href'), 'The feed icon was found.');

    // Test feed display attached to page display with arguments.     $this->drupalGet('test-feed-icon/' . $node->id());
    


  /** * Adds the array of display options to the view, with appropriate overrides. */
  protected function addDisplays(View $view$display_options$form, FormStateInterface $form_state) {
    // Initialize and store the view executable to get the display plugin     // instances.     $executable = $view->getExecutable();

    // Display: Default     $default_display = $executable->newDisplay('default', 'Default', 'default');
    foreach ($display_options['default'] as $option => $value) {
      $default_display->setOption($option$value);
    }

    // Display: Page     if (isset($display_options['page'])) {
      $display = $executable->newDisplay('page', 'Page', 'page_1');
      // The page display is usually the main one (from the user's point of       // view). Its options should therefore become the overall view defaults,       // so that new displays which are added later automatically inherit them.       $this->setDefaultOptions($display_options['page']$display$default_display);

      

  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. */
  public function getStyle() {
    if (!isset($this->style_plugin)) {
      

  protected function getBasicPageView() {
    $view = Views::getView('test_view');

    // In order to test exposed filters, we have to disable     // the exposed forms cache.     \Drupal::service('views.exposed_form_cache')->reset();

    $view->newDisplay('page', 'Page', 'page_1');
    return $view;
  }

  public function testFilterStringEqual() {
    $view = Views::getView('test_view');
    $view->setDisplay();

    // Change the filtering     $view->displayHandlers->get('default')->overrideOption('filters', [
      'name' => [
        'id' => 'name',
        
$options['row']['contains']['type']['default'] = 'rss_fields';
    $options['defaults']['default']['style'] = FALSE;
    $options['defaults']['default']['row'] = FALSE;

    return $options;
  }

  /** * {@inheritdoc} */
  public function newDisplay() {
    parent::newDisplay();

    // 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().     if (empty($this->options['row']['type']) || $this->options['row']['type'] === 'rss_fields') {
      $row_plugins = Views::fetchPluginNames('row', $this->getType()[$this->view->storage->get('base_table')]);
      $default_row_plugin = key($row_plugins);

      $options = $this->getOption('row');
      $options['type'] = $default_row_plugin;
      $this->setOption('row', $options);
    }
Home | Imprint | This part of the site doesn't use cookies.