You are here

function _entityqueue_queue_ensure_instance in Entityqueue 7

Makes sure that a entityreference field instance exists for a queue.

Parameters

EntityQueue $queue: An EntityQueue object.

3 calls to _entityqueue_queue_ensure_instance()
entityqueue_install in ./entityqueue.install
Implements hook_install().
entityqueue_queue_load_multiple in ./entityqueue.module
Loads multiple queues.
entityqueue_queue_save in ./entityqueue.module
Saves a queue.

File

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

Code

function _entityqueue_queue_ensure_instance(EntityQueue $queue) {
  $all_queue_names = variable_get('entityqueue_queue_names', array());
  if (!in_array($queue->name, $all_queue_names)) {
    $all_queue_names[] = $queue->name;
    variable_set('entityqueue_queue_names', $all_queue_names);
  }
  $field_name = _entityqueue_get_target_field_name($queue->target_type);
  $all_eq_fields = variable_get('entityqueue_field_names', array());
  if (!in_array($field_name, $all_eq_fields)) {
    $all_eq_fields[] = $field_name;
    variable_set('entityqueue_field_names', $all_eq_fields);
  }
  $handler_settings = array(
    'behaviors' => array(
      'entityqueue' => array(
        'status' => 1,
      ),
    ),
  );
  if (!field_info_instance('entityqueue_subqueue', $field_name, $queue->name)) {
    _entityqueue_create_entityreference_field($queue, $field_name, 'entityqueue_subqueue', $queue->name, t('Queue items'), 0, array(), $handler_settings);
  }
}