You are here

IdArgumentBase.php in Bibliography & Citation 2.0.x

Same filename and directory in other branches
  1. 8 modules/bibcite_entity/src/Plugin/views/argument/IdArgumentBase.php

File

modules/bibcite_entity/src/Plugin/views/argument/IdArgumentBase.php
View source
<?php

namespace Drupal\bibcite_entity\Plugin\views\argument;

use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\views\Plugin\views\argument\NumericArgument;

/**
 * Class IdArgumentBase.
 */
abstract class IdArgumentBase extends NumericArgument {

  /**
   * The entity storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Constructs the IdArgumentBase 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\Core\Entity\EntityStorageInterface $storage
   *   The entity storage.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->storage = $storage;
  }

  /**
   * Override the behavior of titleQuery(). Get the title of the entity.
   */
  public function titleQuery() {
    $titles = [];
    $entities = $this->storage
      ->loadMultiple($this->value);
    foreach ($entities as $entity) {
      $titles[] = $entity
        ->label();
    }
    return $titles;
  }

}

Classes

Namesort descending Description
IdArgumentBase Class IdArgumentBase.