executableFactory example

if (!$this->display_handler->acceptAttachments()) {
      return;
    }

    $this->is_attachment = TRUE;
    // Find out which other displays attach to the current one.     foreach ($this->display_handler->getAttachedDisplays() as $id) {
      $display_handler = $this->displayHandlers->get($id);
      // Only attach enabled attachments that the user has access to.       if ($display_handler->isEnabled() && $display_handler->access()) {
        $cloned_view = Views::executableFactory()->get($this->storage);
        $display_handler->attachTo($cloned_view$this->current_display, $this->element);
      }
    }
    $this->is_attachment = FALSE;
  }

  /** * Determines if the given user has access to the view. * * Note that this sets the display handler if it hasn't been set. * * @param string $displays * The machine name of the display. * @param \Drupal\Core\Session\AccountInterface $account * The user object. * * @return bool * TRUE if the user has access to the view, FALSE otherwise. */

  protected $module = 'views';

  /** * {@inheritdoc} */
  public function getExecutable() {
    // Ensure that an executable View is available.     if (!isset($this->executable)) {
      $this->executable = Views::executableFactory()->get($this);
    }

    return $this->executable;
  }

  /** * {@inheritdoc} */
  public function createDuplicate() {
    $duplicate = parent::createDuplicate();
    unset($duplicate->executable);
    
$display['display_options']['access']['options']['role'] = [
      $this->normalRole => $this->normalRole,
    ];
    $view->save();
    $this->container->get('router.builder')->rebuildIfNeeded();
    $expected = [
      'config' => ['user.role.' . $this->normalRole],
      'module' => ['user', 'views_test_data'],
    ];
    $this->assertSame($expected$view->calculateDependencies()->getDependencies());

    $executable = Views::executableFactory()->get($view);
    $executable->setDisplay('page_1');

    $access_plugin = $executable->display_handler->getPlugin('access');
    $this->assertInstanceOf(Role::class$access_plugin);

    // Test the access() method on the access plugin.     $this->assertFalse($executable->display_handler->access($this->webUser));
    $this->assertTrue($executable->display_handler->access($this->normalUser));

    $this->drupalLogin($this->webUser);
    $this->drupalGet('test-role');
    

  public static function getView($id) {
    $view = \Drupal::entityTypeManager()->getStorage('view')->load($id);
    if ($view) {
      return static::executableFactory()->get($view);
    }
    return NULL;
  }

  /** * Fetches a list of all base tables available. * * @param string $type * Either 'display', 'style' or 'row'. * @param string $key * For style plugins, this is an optional type to restrict to. May be * 'normal', 'summary', 'feed' or others based on the needs of the display. * @param array $base * An array of possible base tables. * * @return array * A keyed array of in the form of 'base_table' => 'Description'. */
Home | Imprint | This part of the site doesn't use cookies.