You are here

function entityqueue_subqueue_remove_item in Entityqueue 7

Removes an item from a subqueue.

Parameters

\EntitySubqueue $subqueue: An entity subqueue.

string|int $reference_id: An entity ID to remove from the subqueue.

File

./entityqueue.module, line 594
Allows users to collect entities in arbitrarily ordered lists.

Code

function entityqueue_subqueue_remove_item(EntitySubqueue $subqueue, $reference_id) {

  // Get the corresponding queue for this subqueue.
  $queue = entityqueue_queue_load($subqueue->queue);
  $field_name = _entityqueue_get_target_field_name($queue->target_type);

  // Filter the field items and remove the referenced ID.
  $field_items = field_get_items('entityqueue_subqueue', $subqueue, $field_name);
  $field_items = array_filter($field_items, function ($value) use ($reference_id) {
    return $value['target_id'] != $reference_id;
  });

  // Set the filtered item list on the subqueue.
  $langcode = field_language('entityqueue_subqueue', $subqueue, $field_name, NULL);
  $subqueue->{$field_name}[$langcode] = $field_items;
  $subqueue
    ->save();
}