function _entityqueue_create_entityreference_field in Entityqueue 7
Creates an instance of a entityreference field on the specified bundle.
Parameters
EntityQueue $queue: An EntityQueue object.
string $field_name: The name of the field; if it already exists, a new instance of the existing field will be created.
string $entity_type: The type of entity the field instance will be attached to.
string $bundle: The bundle name of the entity the field instance will be attached to.
string $label: The label of the field instance.
int $weight: The default weight of the field instance widget and display.
array $display: An array of default display data used for the entity's current view modes.
array $handler_settings: An array of Entityrefence field handler settings.
1 call to _entityqueue_create_entityreference_field()
- _entityqueue_queue_ensure_instance in ./
entityqueue.module - Makes sure that a entityreference field instance exists for a queue.
File
- ./
entityqueue.module, line 819 - Allows users to collect entities in arbitrarily ordered lists.
Code
function _entityqueue_create_entityreference_field($queue, $field_name, $entity_type, $bundle, $label, $weight = 0, $display = array(), $handler_settings = array()) {
// If a field type we know should exist isn't found, clear the Field cache.
if (!field_info_field_types('entityreference')) {
field_cache_clear();
}
// Look for or add the specified entityreference field to the requested entity
// bundle.
$field = field_read_field($field_name);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'entityreference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'entity_types' => array(
$entity_type,
),
'translatable' => FALSE,
'settings' => array(
'target_type' => $queue->target_type,
'handler' => 'entityqueue',
'handler_settings' => $handler_settings,
),
);
field_create_field($field);
}
$instance = field_read_instance($entity_type, $field_name, $bundle);
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'label' => $label,
'required' => FALSE,
'settings' => array(),
'widget' => array(
'type' => 'entityqueue_dragtable',
'weight' => $weight,
'settings' => array(),
),
'display' => $display,
);
field_create_instance($instance);
}
}