executeDisplay example

        // $view_array variable, since contextual_preprocess() requires that they         // be attached to an array (not an object) in order to process them. For         // our purposes, it doesn't matter what we attach them to, since once they         // are processed by contextual_preprocess() they will appear in the         // $title_suffix variable (which we will then render in         // views-view.html.twig).         $view->setDisplay($element['#display_id']);
        // Add the result of the executed view as a child element so any         // #pre_render elements for the view will get processed. A #pre_render         // element cannot be added to the main element as this is already inside         // a #pre_render callback.         $element['view_build'] = $view->executeDisplay($element['#display_id']$element['#arguments']);

        if (isset($element['view_build']['#title'])) {
          $element['#title'] = &$element['view_build']['#title'];
        }

        if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
          // views_add_contextual_links() needs the following information in           // order to be attached to the view.           $element['#view_id'] = $view->storage->id();
          $element['#view_display_show_admin_links'] = $view->getShowAdminLinks();
          $element['#view_display_plugin_id'] = $view->display_handler->getPluginId();
          
$view = Views::getView('test_argument_default_fixed');
    $view->setDisplay();
    $options = $view->display_handler->getOption('arguments');
    $options['null']['default_argument_options']['argument'] = $random;
    $view->display_handler->overrideOption('arguments', $options);
    $view->initHandlers();

    $this->assertEquals($random$view->argument['null']->getDefaultArgument(), 'Fixed argument should be used by default.');

    // Make sure that a normal argument provided is used     $random_string = $this->randomMachineName();
    $view->executeDisplay('default', [$random_string]);

    $this->assertEquals($random_string$view->args[0], 'Provided argument should be used.');
  }

  /** * @todo Test php default argument. */
  // function testArgumentDefaultPhp() {}
  /** * Tests node default argument. */
/** * Tests the general offset functionality. */
  protected function _testOffset() {
    $view = Views::getView('test_filter_date_between');

    // Test offset for simple operator.     $view->initHandlers();
    $view->filter['created']->operator = '>';
    $view->filter['created']->value['type'] = 'offset';
    $view->filter['created']->value['value'] = '+1 hour';
    $view->executeDisplay('default');
    $expected_result = [
      ['nid' => $this->nodes[3]->id()],
    ];
    $this->assertIdenticalResultset($view$expected_result$this->map);
    $view->destroy();

    // Test offset for between operator.     $view->initHandlers();
    $view->filter['created']->operator = 'between';
    $view->filter['created']->value['type'] = 'offset';
    $view->filter['created']->value['max'] = '+2 days';
    
for ($i = 0; $i < $count$i++) {
        $node = $setting;
        $node['title'] = $char . $this->randomString(3);
        $node = $this->drupalCreateNode($node);
        $nodes_by_char[$char][] = $node;
      }
    }

    // Execute glossary view     $view = Views::getView('glossary');
    $view->setDisplay('attachment_1');
    $view->executeDisplay('attachment_1');

    // Check that the amount of nodes per char.     foreach ($view->result as $item) {
      $this->assertEquals($nodes_per_char[$item->title_truncated]$item->num_records);
    }

    // Enable the glossary to be displayed.     $view->storage->enable()->save();
    $this->container->get('router.builder')->rebuildIfNeeded();
    $url = Url::fromRoute('view.glossary.page_1');

    

  protected function getDisplayExecutionResults(string $match = NULL, string $match_operator = 'CONTAINS', int $limit = 0, array $ids = NULL) {
    $display_name = $this->getConfiguration()['view']['display_name'];
    $arguments = $this->getConfiguration()['view']['arguments'];
    $results = [];
    if ($this->initializeView($match$match_operator$limit$ids)) {
      $results = $this->view->executeDisplay($display_name$arguments);
    }
    return $results;
  }

  /** * Strips all admin and anchor tags from a result list. * * These results are usually displayed in an autocomplete field, which is * surrounded by anchor tags. Most tags are allowed inside anchor tags, except * for other anchor tags. * * @param array $results * The result list. * * @return array * The provided result list with anchor tags removed. */
Home | Imprint | This part of the site doesn't use cookies.