You are here

class Fid in Drupal 10

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

Argument handler to accept multiple file ids.

Plugin annotation

@ViewsArgument("file_fid");

Hierarchy

Expanded class hierarchy of Fid

1 string reference to 'Fid'
views.view.files.yml in core/modules/file/config/optional/views.view.files.yml
core/modules/file/config/optional/views.view.files.yml

File

core/modules/file/src/Plugin/views/argument/Fid.php, line 17

Namespace

Drupal\file\Plugin\views\argument
View source
class Fid extends NumericArgument implements ContainerFactoryPluginInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a Drupal\file\Plugin\views\argument\Fid 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\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
  }

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

  /**
   * Override the behavior of titleQuery(). Get the filenames.
   */
  public function titleQuery() {
    $storage = $this->entityTypeManager
      ->getStorage('file');
    $fids = $storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->condition('fid', $this->value, 'IN')
      ->execute();
    $files = $storage
      ->loadMultiple($fids);
    $titles = [];
    foreach ($files as $file) {
      $titles[] = $file
        ->getFilename();
    }
    return $titles;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Fid::$entityTypeManager protected property The entity type manager.
Fid::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
Fid::titleQuery public function Override the behavior of titleQuery(). Get the filenames. Overrides NumericArgument::titleQuery
Fid::__construct public function Constructs a Drupal\file\Plugin\views\argument\Fid 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