You are here

public function SmartQueue::onQueuePostDelete in Entityqueue 8

Acts on deleted entity queues before the delete hook is invoked.

Parameters

\Drupal\entityqueue\EntityQueueInterface $queue: The entity queue object.

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

Overrides Multiple::onQueuePostDelete

File

modules/entityqueue_smartqueue/src/Plugin/EntityQueueHandler/SmartQueue.php, line 235

Class

SmartQueue
Plugin annotation @EntityQueueHandler( id = "smartqueue", title = @Translation("Smart queue"), description = @Translation("Provides automated subqueues for each entity of a given type."), )

Namespace

Drupal\entityqueue_smartqueue\Plugin\EntityQueueHandler

Code

public function onQueuePostDelete(EntityQueueInterface $queue, EntityStorageInterface $storage) {

  // Create batch operation to delete all the subqueues when the parent queue is deleted.
  $subqueue_ids = $this->entityTypeManager
    ->getStorage('entity_subqueue')
    ->getQuery()
    ->condition('queue', $queue
    ->id())
    ->execute();
  $subqueue_id_chunks = array_chunk($subqueue_ids, 20);
  $operations = [];
  foreach ($subqueue_id_chunks as $subqueue_id_chunk) {
    $operations[] = [
      [
        $this,
        'deleteSubqueues',
      ],
      [
        $subqueue_id_chunk,
      ],
    ];
  }
  $batch = [
    'title' => t('Deleting subqueues'),
    'operations' => $operations,
    'finished' => [
      get_class($this),
      'deleteSubqueuesFinished',
    ],
  ];
  batch_set($batch);
}