class Vid

Same name and namespace in other branches
  1. 11.x core/modules/node/src/Plugin/views/argument/Vid.php \Drupal\node\Plugin\views\argument\Vid
  2. 10 core/modules/node/src/Plugin/views/argument/Vid.php \Drupal\node\Plugin\views\argument\Vid
  3. 8.9.x core/modules/node/src/Plugin/views/argument/Vid.php \Drupal\node\Plugin\views\argument\Vid

Argument handler to accept a node revision id.

Plugin annotation

@ViewsArgument("node_vid");

Hierarchy

Expanded class hierarchy of Vid

1 file declares its use of Vid
ArgumentNodeRevisionIdTest.php in core/modules/node/tests/src/Kernel/Views/ArgumentNodeRevisionIdTest.php
103 string references to 'Vid'
ContentEntityTest::testMediaSource in core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
Tests media source plugin.
ContentEntityTest::testNodeSource in core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
Tests node source plugin.
ContentEntityTest::testTermSource in core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
Tests term source plugin.
content_moderation_test_views_views_query_alter in core/modules/content_moderation/tests/modules/content_moderation_test_views/content_moderation_test_views.module
Implements hook_views_query_alter().
D6TermNodeDeriver::getDerivativeDefinitions in core/modules/taxonomy/src/Plugin/migrate/D6TermNodeDeriver.php

... See full list

File

core/modules/node/src/Plugin/views/argument/Vid.php, line 15

Namespace

Drupal\node\Plugin\views\argument
View source
class Vid extends NumericArgument {
  use DeprecatedServicePropertyTrait;
  
  /**
   * {@inheritdoc}
   */
  protected $deprecatedProperties = [
    'database' => 'database',
  ];
  
  /**
   * The node storage.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected $nodeStorage;
  
  /**
   * Constructs a \Drupal\node\Plugin\views\argument\Vid object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\node\NodeStorageInterface $node_storage
   *   The node storage.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, $node_storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    if (!$node_storage instanceof NodeStorageInterface) {
      @trigger_error('Passing the database service to ' . __METHOD__ . '() is deprecated in drupal:9.2.0 and will be removed before drupal:10.0.0. See https://www.drupal.org/node/3178412', E_USER_DEPRECATED);
      $node_storage = func_get_arg(4);
    }
    if (!$node_storage instanceof NodeStorageInterface) {
      throw new \InvalidArgumentException('The fourth argument must implement \\Drupal\\node\\NodeStorageInterface.');
    }
    $this->nodeStorage = $node_storage;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager')
      ->getStorage('node'));
  }
  
  /**
   * Override the behavior of title(). Get the title of the revision.
   */
  public function titleQuery() {
    $titles = [];
    $results = $this->nodeStorage
      ->getAggregateQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      ->groupBy('title')
      ->condition('vid', $this->value, 'IN')
      ->execute();
    foreach ($results as $result) {
      $titles[] = $result['title'];
    }
    return $titles;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.