90564d5bb64064405dad4f1d62206bca1d1cb408
[yaffs-website] / web / core / modules / aggregator / src / Plugin / views / argument / Fid.php
1 <?php
2
3 namespace Drupal\aggregator\Plugin\views\argument;
4
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\views\Plugin\views\argument\NumericArgument;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 /**
10  * Argument handler to accept an aggregator feed id.
11  *
12  * @ingroup views_argument_handlers
13  *
14  * @ViewsArgument("aggregator_fid")
15  */
16 class Fid extends NumericArgument {
17
18   /**
19    * The entity manager service.
20    *
21    * @var \Drupal\Core\Entity\EntityManagerInterface
22    */
23   protected $entityManager;
24
25   /**
26    * Constructs a Drupal\Component\Plugin\PluginBase object.
27    *
28    * @param array $configuration
29    *   A configuration array containing information about the plugin instance.
30    * @param string $plugin_id
31    *   The plugin_id for the plugin instance.
32    * @param mixed $plugin_definition
33    *   The plugin implementation definition.
34    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
35    *   The entity manager.
36    */
37   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
38     parent::__construct($configuration, $plugin_id, $plugin_definition);
39     $this->entityManager = $entity_manager;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
46     return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'));
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function titleQuery() {
53     $titles = [];
54
55     $feeds = $this->entityManager->getStorage('aggregator_feed')->loadMultiple($this->value);
56     foreach ($feeds as $feed) {
57       $titles[] = $feed->label();
58     }
59     return $titles;
60   }
61
62 }