| Versionen | |
|---|---|
| drupal7 | _field_invoke($op, $obj_type, &$object, &$a = NULL, &$b = NULL, $default = FALSE) |
Invoke a field hook.
$op Possible operations include:
$obj_type The type of $object; e.g. 'node' or 'user'.
$object The fully formed $obj_type object.
$a
$b
$default
modules/
<?php
function _field_invoke($op, $obj_type, &$object, &$a = NULL, &$b = NULL, $default = FALSE) {
list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
$instances = field_info_instances($bundle);
$return = array();
foreach ($instances as $instance) {
$field_name = $instance['field_name'];
$field = field_info_field($field_name);
$items = isset($object->$field_name) ? $object->$field_name : array();
$function = $default ? 'field_default_' . $op : $field['module'] . '_field_' . $op;
if (drupal_function_exists($function)) {
$result = $function($obj_type, $object, $field, $instance, $items, $a, $b);
if (is_array($result)) {
$return = array_merge($return, $result);
}
elseif (isset($result)) {
$return[] = $result;
}
}
// Populate field values back in the object, but avoid replacing missing
// fields with an empty array (those are not equivalent on update).
if ($items !== array() || property_exists($object, $field_name)) {
$object->$field_name = $items;
}
}
return $return;
}
?>
Kommentare
Kommentar hinzufügen