/** * Constructs the EntityQueue selection handler. */ protected function __construct($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { parent::__construct($field, $instance, $entity_type, $entity); $queue_name = NULL; if (!empty($entity->queue)) { $queue_name = $entity->queue; } elseif (!empty($instance['bundle'])) { $queue_name = $instance['bundle']; } if (!empty($queue_name)) { $this->queue = entityqueue_queue_load($queue_name); } // Override the entityreference settings with our own. $this->field['settings']['handler_settings']['target_bundles'] = NULL; }
/** * Overrides EntityReference_BehaviorHandler_Abstract::presave(). */ public function presave($entity_type, $entity, $field, $instance, $langcode, &$items) { if ($entity_type == 'entityqueue_subqueue') { $queue = entityqueue_queue_load($entity->queue); $max_size = $queue->settings['max_size']; $act_as_queue = isset($queue->settings['act_as_queue']) ? $queue->settings['act_as_queue'] : 0; if ($act_as_queue) { $empty_target_id = create_function('$value', 'return (!empty($value["target_id"])) ? TRUE : FALSE;'); $eq_items = array_filter($items, $empty_target_id); if (count($eq_items) > $max_size && $max_size > 0) { // Keep up to $max_size items $items = array_slice($eq_items, -$max_size); } } } }