- Issue created by @idiaz.roncero
As far as I have tested (on a custom module heavily based on this one), the following lines of code might be unnecessary:
// Add entity to each subqueue.
foreach ($subqueues as $subqueue) {
$items = $subqueue->get('items')->getValue();
// Deetermine if we should remove an item from the list to avoid exceeding
// the maximum number of items.
$remove_item = !empty($queue_settings['max_size']) && count($items) >= $queue_settings['max_size'];
if (isset($entity_settings['handler_settings']['auto_entityqueue']['insert_front']) && $entity_settings['handler_settings']['auto_entityqueue']['insert_front']) {
!$remove_item or array_pop($items);
array_unshift($items, array('target_id' => $entity_id));
}
else {
!$remove_item or array_shift($items);
array_push($items, array('target_id' => $entity_id));
}
$subqueue->set('items', $items);
$subqueue->save();
}
There is an already existing $subqueue->addItem($entity)
method that handles the addition to items to a queue and it seems to respect every existing queue config (append to top/bottom, min and max items, removing extra items, etc).
So, the above mentioned code could be refactored to something as simple as this (maybe it will need some additional sanity check, but not much more) and delegate all functionality to the original module.
// Add entity to each subqueue.
foreach ($subqueues as $subqueue) {
$subqueue->addItem($entity)->save();
}
This will be DRYer and safer, as any new behavior / functionality added on the original Entityqueue module (new queue configs, etc) should be immediately available.
Active
1.0
Code