You are here

function _editablefields_content_widget_invoke_field in Editable Fields 5

Same name and namespace in other branches
  1. 5.3 editablefields.module \_editablefields_content_widget_invoke_field()
  2. 5.2 editablefields.module \_editablefields_content_widget_invoke_field()

Invoke a widget hook for one field.

1 call to _editablefields_content_widget_invoke_field()
_editablefields_content_form_field in ./editablefields.module

File

./editablefields.module, line 176

Code

function _editablefields_content_widget_invoke_field($op, &$node, $field, $widget_types) {
  $return = array();
  $node_field = isset($node->{$field}['field_name']) ? $node->{$field}['field_name'] : array();
  $module = $widget_types[$field['widget']['type']]['module'];
  $function = $module . '_widget';
  if (function_exists($function)) {

    // If we're building a node creation form, pre-fill with default values
    if ($op == 'prepare form values' && empty($node->nid)) {
      $node_field = array_merge($node_field, content_default_value($node, $field, $node_field));
    }
    $result = $function($op, $node, $field, $node_field);
    if (is_array($result) && $op == 'form') {
      $result[$field['field_name']]['#weight'] = $field['widget']['weight'];
    }
    if (is_array($result)) {
      $return = array_merge($return, $result);
    }
    else {
      if (isset($result)) {
        $return[] = $result;
      }
    }
  }

  // test for values in $node_field in case modules added items
  if (is_object($node) && (isset($node->{$field}['field_name']) || count($node_field))) {
    $node->{$field}['field_name'] = $node_field;
  }
  return $return;
}