_field_invoke_multiple

  1. drupal
    1. drupal7
Versionen
drupal7 _field_invoke_multiple($op, $obj_type, &$objects, &$a = NULL, &$b = NULL, $default = FALSE)

Invoke a field operation across fields on multiple objects.

Übergabeparameter

$op Possible operations include:

  • load

$obj_type The type of $object; e.g. 'node' or 'user'.

$objects An array of objects, keyed by object id.

$a

  • The $age parameter in the 'load' operation.
  • Otherwise NULL.

$b Currently always NULL.

$default

  • TRUE: use the default field implementation of the field hook.
  • FALSE: use the field module's implementation of the field hook.

Rückgabewert

An array of returned values keyed by object id.

Verwandte Themen

▾ 2 functions call _field_invoke_multiple()

_field_attach_load in modules/field/field.attach.inc
Load all fields for the most current version of each of a set of objects of a single object type.
_field_invoke_multiple_default in modules/field/field.attach.inc
Invoke field.module's version of a field hook on multiple objects.

Code

modules/field/field.attach.inc, line 209

<?php
function _field_invoke_multiple($op, $obj_type, &$objects, &$a = NULL, &$b = NULL, $default = FALSE) {
  $fields = array();
  $grouped_instances = array();
  $grouped_objects = array();
  $grouped_items = array();
  $return = array();

  // Preparation:
  // - Get the list of fields contained in the various bundles.
  // - For each field, group the corresponding instances, objects and field
  //   values.
  // - Initialize the return value for each object.
  foreach ($objects as $object) {
    list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
    foreach (field_info_instances($bundle) as $instance) {
      $field_name = $instance['field_name'];
      if (!isset($grouped_fields[$field_name])) {
        $fields[$field_name] = field_info_field($field_name);
      }
      $grouped_instances[$field_name][$id] = $instance;
      $grouped_objects[$field_name][$id] = &$objects[$id];
      $grouped_items[$field_name][$id] = isset($object->$field_name) ? $object->$field_name : array();
    }
    $return[$id] = array();
  }

  // Call each field's operation.
  foreach ($fields as $field_name => $field) {
    if (!empty($field)) {
      $function = $default ? 'field_default_' . $op : $field['module'] . '_field_' . $op;
      if (drupal_function_exists($function)) {
        $results = $function($obj_type, $grouped_objects[$field_name], $field, $grouped_instances[$field_name], $grouped_items[$field_name], $a, $b);
        // Merge results by object.
        if (isset($results)) {
          foreach ($results as $id => $result) {
            if (is_array($result)) {
              $return[$id] = array_merge($return[$id], $result);
            }
            else {
              $return[$id][] = $result;
            }
          }
        }
      }
    }

    // Populate field values back in the objects, but avoid replacing missing
    // fields with an empty array (those are not equivalent on update).
    foreach ($grouped_objects[$field_name] as $id => $object) {
      if ($grouped_items[$field_name][$id] !== array() || property_exists($object, $field_name)) {
        $object->$field_name = $grouped_items[$field_name][$id];
      }
    }
  }

  return $return;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen