getExecutable example


  public function getDisplayTabs(ViewUI $view) {
    $executable = $view->getExecutable();
    $executable->initDisplay();
    $display_id = $this->displayID;
    $tabs = [];

    // Create a tab for each display.     foreach ($view->get('display') as $id => $display) {
      // Get an instance of the display plugin, to make sure it will work in the       // UI.       $display_plugin = $executable->displayHandlers->get($id);
      if (empty($display_plugin)) {
        continue;
      }
public function testSerialization() {
    $storage = new View([], 'view');
    $executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
      ->disableOriginalConstructor()
      ->setConstructorArgs([$storage])
      ->getMock();
    $storage->set('executable', $executable);

    $view_ui = new ViewUI($storage);

    // Make sure the executable is returned before serializing.     $this->assertInstanceOf('Drupal\views\ViewExecutable', $view_ui->getExecutable());

    $serialized = serialize($view_ui);

    // Make sure the ViewExecutable class is not found in the serialized string.     $this->assertStringNotContainsString('"Drupal\views\ViewExecutable"', $serialized);

    $unserialized = unserialize($serialized);
    $this->assertInstanceOf('Drupal\views_ui\ViewUI', $unserialized);
  }

}


  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $view = $form_state->get('view');
    $display_id = $form_state->get('display_id');
    $type = $form_state->get('type');

    $types = ViewExecutable::getHandlerTypes();
    $executable = $view->getExecutable();
    if (!$executable->setDisplay($display_id)) {
      $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
      return $form;
    }
    $display = &$executable->displayHandlers->get($display_id);
    $form['#title'] = $this->t('Rearrange @type', ['@type' => $types[$type]['ltitle']]);
    $form['#section'] = $display_id . 'rearrange-item';

    if ($display->defaultableSections($types[$type]['plural'])) {
      $section = $types[$type]['plural'];
      $form_state->set('section', $section);
      
$this->assertViewsCacheTags($view$result_tags_page_1$do_assert_views_caches$render_tags_page_1);
    $this->assertViewsCacheTagsFromStaticRenderArray($view$render_tags_page_1$do_assert_views_caches);
  }

  /** * Ensure that the view renderable contains the cache contexts. */
  public function testBuildRenderableWithCacheContexts() {
    $view = View::load('test_view');
    $display =& $view->getDisplay('default');
    $display['cache_metadata']['contexts'] = ['views_test_cache_context'];
    $executable = $view->getExecutable();

    $build = $executable->buildRenderable();
    $this->assertEquals(['views_test_cache_context']$build['#cache']['contexts']);
  }

  /** * Ensures that saving a view calculates the cache contexts. */
  public function testViewAddCacheMetadata() {
    $view = View::load('test_display');
    $view->save();

    
    $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());
    
/** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Check all Views for displays with an exposed filter block.     foreach ($this->viewStorage->loadMultiple() as $view) {
      // Do not return results for disabled views.       if (!$view->status()) {
        continue;
      }
      $executable = $view->getExecutable();
      $executable->initDisplay();
      foreach ($executable->displayHandlers as $display) {
        if (isset($display) && $display->getOption('exposed_block')) {
          // Add a block definition for the block.           if ($display->usesExposedFormInBlock()) {
            $delta = $view->id() . '-' . $display->display['id'];
            $desc = $this->t('Exposed form: @view-@display_id', ['@view' => $view->id(), '@display_id' => $display->display['id']]);
            $this->derivatives[$delta] = [
              'admin_label' => $desc,
              'config_dependencies' => [
                'config' => [
                  

  protected function getDisplaysList(EntityInterface $view) {
    $displays = [];

    $executable = $view->getExecutable();
    $executable->initDisplay();
    foreach ($executable->displayHandlers as $display) {
      $rendered_path = FALSE;
      $definition = $display->getPluginDefinition();
      if (!empty($definition['admin'])) {
        if ($display->hasPath()) {
          $path = $display->getPath();
          if ($view->status() && !str_contains($path, '%')) {
            // Wrap this in a try/catch as trying to generate links to some             // routes may throw a NotAcceptableHttpException if they do not             // respond to HTML, such as RESTExports.


  /** * Tests that all Default views work as expected. */
  public function testDefaultViews() {
    // Get all default views.     $controller = $this->container->get('entity_type.manager')->getStorage('view');
    $views = $controller->loadMultiple();

    foreach ($views as $name => $view_storage) {
      $view = $view_storage->getExecutable();
      $view->initDisplay();
      foreach ($view->storage->get('display') as $display_id => $display) {
        $view->setDisplay($display_id);

        // Add any args if needed.         if (array_key_exists($name$this->viewArgMap)) {
          $view->preExecute($this->viewArgMap[$name]);
        }

        $view->execute();

        
/** * {@inheritdoc} */
  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']);

    
/** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $view = $form_state->get('view');

    $form['#title'] = $this->t('View analysis');
    $form['#section'] = 'analyze';

    $analyzer = Views::analyzer();
    $messages = $analyzer->getMessages($view->getExecutable());

    $form['analysis'] = [
      '#prefix' => '<div class="js-form-item form-item">',
      '#suffix' => '</div>',
      '#markup' => $analyzer->formatMessages($messages),
    ];

    // Inform the standard button function that we want an OK button.     $form_state->set('ok_button', TRUE);
    $view->getStandardButtons($form$form_state, 'views_ui_analyze_view_form');
    return $form;
  }
/** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $links = [];
    $views = Views::getApplicableViews('uses_menu_links');

    foreach ($views as $data) {
      [$view_id$display_id] = $data;
      /** @var \Drupal\views\ViewExecutable $executable */
      $executable = $this->viewStorage->load($view_id)->getExecutable();
      $executable->initDisplay();
      $display = $executable->displayHandlers->get($display_id);

      if (($display instanceof DisplayMenuInterface) && ($result = $display->getMenuLinks())) {
        foreach ($result as $link_id => $link) {
          $links[$link_id] = $link + $base_plugin_definition;
        }
      }
    }

    return $links;
  }
/** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];

    $view_route_names = $this->state->get('views.view_route_names');
    foreach ($this->getApplicableMenuViews() as $pair) {
      /** @var \Drupal\views\ViewExecutable $executable */
      [$view_id$display_id] = $pair;
      $executable = $this->viewStorage->load($view_id)->getExecutable();

      $executable->setDisplay($display_id);
      $menu = $executable->display_handler->getOption('menu');
      if (in_array($menu['type']['tab', 'default tab'])) {
        $plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id;
        $route_name = $view_route_names[$executable->storage->id() . '.' . $display_id];

        // Don't add a local task for views which override existing routes.         // @todo Alternative it could just change the existing entry.         if ($route_name != $plugin_id) {
          continue;
        }
$view = $form_state->get('view');
    $display_id = $form_state->get('display_id');
    $type = $form_state->get('type');

    $form = [
      'options' => [
        '#theme_wrappers' => ['container'],
        '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
      ],
    ];

    $executable = $view->getExecutable();
    if (!$executable->setDisplay($display_id)) {
      $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
      return $form;
    }
    $display = &$executable->displayHandlers->get($display_id);

    $types = ViewExecutable::getHandlerTypes();
    $ltitle = $types[$type]['ltitle'];
    $section = $types[$type]['plural'];

    if (!empty($types[$type]['type'])) {
      
// Test disabled views.     $this->assertEquals($this->formatViewOptions($expected_disabled), Views::getViewsAsOptions(FALSE, 'disabled'), 'Expected disabled options array was returned.');

    // Test the sort parameter.     $all_views_sorted = $all_views;
    ksort($all_views_sorted);
    $this->assertSame(array_keys($all_views_sorted)array_keys(Views::getViewsAsOptions(TRUE, 'all', NULL, FALSE, TRUE)), 'All view id keys returned in expected sort order');

    // Test $exclude_view parameter.     $this->assertArrayNotHasKey('archive', Views::getViewsAsOptions(TRUE, 'all', 'archive'));
    $this->assertArrayNotHasKey('archive:default', Views::getViewsAsOptions(FALSE, 'all', 'archive:default'));
    $this->assertArrayNotHasKey('archive', Views::getViewsAsOptions(TRUE, 'all', $archive->getExecutable()));

    // Test the $opt_group parameter.     $expected_opt_groups = [];
    foreach ($all_views as $view) {
      foreach ($view->get('display') as $display) {
        $expected_opt_groups[$view->id()][$view->id() . ':' . $display['id']] = $view->id() . ' : ' . $display['id'];
      }
    }
    $this->assertEquals($expected_opt_groups, Views::getViewsAsOptions(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
  }

  
/** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Check all Views for block displays.     foreach ($this->viewStorage->loadMultiple() as $view) {
      // Do not return results for disabled views.       if (!$view->status()) {
        continue;
      }
      $executable = $view->getExecutable();
      $executable->initDisplay();
      foreach ($executable->displayHandlers as $display) {
        /** @var \Drupal\views\Plugin\views\display\DisplayPluginInterface $display */
        // Add a block plugin definition for each block display.         if (isset($display) && !empty($display->definition['uses_hook_block'])) {
          $delta = $view->id() . '-' . $display->display['id'];

          $admin_label = $display->getOption('block_description');
          if (empty($admin_label)) {
            if ($display->display['display_title'] == $display->definition['title']) {
              $admin_label = $view->label();
            }
Home | Imprint | This part of the site doesn't use cookies.