You are here

function entityqueue_smartqueue_entity_insert in Entityqueue 8

Implements hook_entity_insert().

File

modules/entityqueue_smartqueue/entityqueue_smartqueue.module, line 70
Provides automated subqueues for each entity of a given entity type.

Code

function entityqueue_smartqueue_entity_insert(EntityInterface $entity) {
  $queues = _entityqueue_smartqueue_get_queues($entity
    ->getEntityTypeId());
  foreach ($queues as $queue) {

    // Check if the entity that got inserted is of the relevant bundle.
    if (!in_array($entity
      ->bundle(), $queue
      ->getHandlerConfiguration()['bundles'], TRUE)) {
      continue;
    }
    $subqueue = EntitySubqueue::create([
      'queue' => $queue
        ->id(),
      'name' => $queue
        ->id() . '__' . $entity
        ->id(),
      'title' => $entity
        ->label(),
      'langcode' => $queue
        ->language()
        ->getId(),
      'attached_entity' => $entity,
    ]);
    $subqueue
      ->save();
  }
}