protected function FlexiformElementField::fieldInvoke in Flexiform 7
Invoke field hooks on a specific field.
This method is the equivelant of _field_invoke. For a specific field in flexiform.
See also
2 calls to FlexiformElementField::fieldInvoke()
- FlexiformElementField::fieldInvokeDefault in includes/
element/ field.element.inc - Invoke default field hooks on this element.
- FlexiformElementField::formValidate in includes/
element/ field.element.inc - Validate this element.
File
- includes/
element/ field.element.inc, line 512 - Contains FlexiformElementField class.
Class
- FlexiformElementField
- Class for Field API elements.
Code
protected function fieldInvoke($op, $entity, &$a = NULL, &$b = NULL, $options = array()) {
$entity_type = $this
->getEntityType();
$bundle = $this->bundle;
$default_options = array(
'default' => FALSE,
'deleted' => FALSE,
'language' => NULL,
);
$options += $default_options;
$return = array();
$instance = $this
->getInstance();
$field = $this
->getField();
$field_name = $field['field_name'];
$function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op;
if (function_exists($function)) {
// Determine the list of languages to iterate on.
$available_languages = field_available_languages($entity_type, $field);
$languages = _field_language_suggestion($available_languages, $options['language'], $field_name);
foreach ($languages as $langcode) {
$items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
$result = $function($entity_type, $entity, $field, $instance, $langcode, $items, $a, $b);
if (isset($result)) {
// For hooks with array results, we merge results together.
// For hooks with scalar results, we collect results in an array.
if (is_array($result)) {
$return = array_merge($return, $result);
}
else {
$return[] = $result;
}
}
// Populate $items back in the field values, but avoid replacing missing
// fields with an empty array (those are not equivalent on update).
if ($items !== array() || isset($entity->{$field_name}[$langcode])) {
$entity->{$field_name}[$langcode] = $items;
}
}
}
return $return;
}