1 field.attach.inc | _field_invoke_get_instances($entity_type, $bundle, $options) |
Helper for _field_invoke(): retrieves a list of instances to operate on.
Parameters
$entity_type: The entity type.
$bundle: The bundle name.
$options: An associative array of options, as provided to _field_invoke(). Only the following keys are considered :
- deleted
- field_name
See _field_invoke() for details.
Return value
The array of selected instance definitions.:
Related topics
File
- core/
modules/ field/ field.attach.inc, line 383 - Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.
Code
function _field_invoke_get_instances($entity_type, $bundle, $options) {
if ($options['deleted']) {
// Deleted fields are not included in field_info_instances(), and need to
// be fetched from the database with field_read_instances().
$params = array('entity_type' => $entity_type, 'bundle' => $bundle);
if (isset($options['field_name'])) {
$params['field_name'] = $options['field_name'];
}
$instances = field_read_instances($params, array('include_deleted' => TRUE));
}
elseif (isset($options['field_name'])) {
// Single-field mode by field name: field_info_instance() does the
// filtering.
$instances = array(field_info_instance($entity_type, $options['field_name'], $bundle));
}
else {
$instances = field_info_instances($entity_type, $bundle);
if (isset($options['field_name'])) {
// Single-field mode by field id: we need to loop on each instance to
// find the right one.
foreach ($instances as $instance) {
if ($instance['field_name'] == $options['field_name']) {
$instances = array($instance);
break;
}
}
}
}
return $instances;
}