You are here

function _content_widget_invoke in Content Construction Kit (CCK) 5

Invoke a widget hook.

4 calls to _content_widget_invoke()
content_form in ./content.module
Create fields' form for a content type.
content_submit in ./content.module
Submit form callback for node type fields.
content_validate in ./content.module
Validate form callback to handle node type fields.
content_view in ./content.module
Generate field render arrays.

File

./content.module, line 643
Allows administrators to associate custom fields to content types.

Code

function _content_widget_invoke($op, &$node) {
  $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
  $type = content_types($type_name);
  $widget_types = _content_widget_types();
  $return = array();
  if (count($type['fields'])) {
    foreach ($type['fields'] as $field) {
      $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;
}