Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / entityqueue / src / Plugin / EntityQueueHandler / Multiple.php
1 <?php
2
3 namespace Drupal\entityqueue\Plugin\EntityQueueHandler;
4
5 use Drupal\Core\Entity\EntityStorageInterface;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\entityqueue\EntityQueueHandlerBase;
9 use Drupal\entityqueue\EntityQueueInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Defines an entity queue handler that manages multiple subqueues.
14  *
15  * @EntityQueueHandler(
16  *   id = "multiple",
17  *   title = @Translation("Multiple subqueues")
18  * )
19  */
20 class Multiple extends EntityQueueHandlerBase implements ContainerFactoryPluginInterface {
21
22   /**
23    * The entity type manager.
24    *
25    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
26    */
27   protected $entityTypeManager;
28
29   /**
30    * Constructs a Multiple queue handler object.
31    *
32    * @param array $configuration
33    *   A configuration array containing information about the plugin instance.
34    * @param string $plugin_id
35    *   The plugin ID for the plugin instance.
36    * @param mixed $plugin_definition
37    *   The plugin implementation definition.
38    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
39    *   The entity type manager.
40    */
41   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
42     parent::__construct($configuration, $plugin_id, $plugin_definition);
43
44     $this->entityTypeManager = $entity_type_manager;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
51     return new static(
52       $configuration,
53       $plugin_id,
54       $plugin_definition,
55       $container->get('entity_type.manager')
56     );
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function supportsMultipleSubqueues() {
63     return TRUE;
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function hasAutomatedSubqueues() {
70     return FALSE;
71   }
72
73   /**
74    * {@inheritdoc}
75    */
76   public function onQueuePostDelete(EntityQueueInterface $queue, EntityStorageInterface $storage) {
77     // Delete all the subqueues when the parent queue is deleted.
78     $subqueue_storage = $this->entityTypeManager->getStorage('entity_subqueue');
79
80     $subqueues = $subqueue_storage->loadByProperties([$this->entityTypeManager->getDefinition('entity_subqueue')->getKey('bundle') => $queue->id()]);
81     $subqueue_storage->delete($subqueues);
82   }
83
84 }