function _field_invoke_get_instances

7.x _field_invoke_get_instances($entity_type, $bundle, $options)

Helper for _field_invoke(): retrieves a list of instances to operate on.


$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
  • field_id

See _field_invoke() for details.

Return value

The array of selected instance definitions.

Related topics

3 calls to _field_invoke_get_instances()
field_attach_load in drupal/modules/field/
Loads fields for the current revisions of a group of entities.
_field_invoke in drupal/modules/field/
Invoke a field hook.
_field_invoke_multiple in drupal/modules/field/
Invoke a field hook across fields on multiple entities.


drupal/modules/field/, line 420
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.


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_id'])) {
      // Single-field mode by field id: field_read_instances() does the filtering.
      // Single-field mode by field name is not compatible with the 'deleted'
      // option.
      $params['field_id'] = $options['field_id'];
    $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_id'])) {
      // 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_id'] == $options['field_id']) {
          $instances = array($instance);

  return $instances;