You are here

class Nid in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/src/Plugin/views/argument/Nid.php \Drupal\node\Plugin\views\argument\Nid
  2. 9 core/modules/node/src/Plugin/views/argument/Nid.php \Drupal\node\Plugin\views\argument\Nid

Argument handler to accept a node id.

Plugin annotation

@ViewsArgument("node_nid");

Hierarchy

  • class \Drupal\views\Plugin\views\argument\NumericArgument extends \Drupal\views\Plugin\views\argument\ArgumentPluginBase
    • class \Drupal\node\Plugin\views\argument\Nid

Expanded class hierarchy of Nid

5 string references to 'Nid'
book.views.schema.yml in core/modules/book/config/schema/book.views.schema.yml
core/modules/book/config/schema/book.views.schema.yml
forum_views_data in core/modules/forum/forum.views.inc
Implements hook_views_data().
tracker_views_data in core/modules/tracker/tracker.views.inc
Implements hook_views_data().
views.view.test_dropbutton.yml in core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml
core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml
views.view.test_node_view.yml in core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_view.yml
core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_view.yml

File

core/modules/node/src/Plugin/views/argument/Nid.php, line 14

Namespace

Drupal\node\Plugin\views\argument
View source
class Nid extends NumericArgument {

  /**
   * The node storage.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected $nodeStorage;

  /**
   * Constructs the Nid 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 handler.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, NodeStorageInterface $node_storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $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 node.
   */
  public function titleQuery() {
    $titles = [];
    $nodes = $this->nodeStorage
      ->loadMultiple($this->value);
    foreach ($nodes as $node) {
      $titles[] = $node
        ->label();
    }
    return $titles;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Nid::$nodeStorage protected property The node storage.
Nid::create public static function
Nid::titleQuery public function Override the behavior of title(). Get the title of the node. Overrides NumericArgument::titleQuery
Nid::__construct public function Constructs the Nid object.
NumericArgument::$value public property The actual value which is used for querying.
NumericArgument::buildOptionsForm public function 1
NumericArgument::defineOptions protected function 1
NumericArgument::getContextDefinition public function
NumericArgument::getSortName public function
NumericArgument::query public function 1
NumericArgument::title public function 2