You are here

function content_generate_fields in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 5 content.devel.inc \content_generate_fields()
  2. 6.3 includes/content.devel.inc \content_generate_fields()

Enrich the $node that is about to be saved with arbitrary information in each of its CCK fields.

1 call to content_generate_fields()
content_field in ./content.module
Implementation of hook_field(). Handles common field housekeeping.

File

includes/content.devel.inc, line 20
Functions needed for Devel module integration.

Code

function content_generate_fields(&$node, $field) {
  $type_name = $node->type;
  $type = content_types($type_name);
  $field_types = _content_field_types();
  if (!empty($type['fields'])) {
    foreach ($type['fields'] as $field) {
      $node_field = array();

      // If module handles own multiples, then only call its hook once.
      if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
        $max = 0;
      }
      else {
        switch ($field['multiple']) {
          case 0:
            $max = 0;
            break;
          case 1:
            $max = rand(0, 3);

            //just an arbitrary number for 'unlimited'
            break;
          default:
            $max = $field['multiple'];
            break;
        }
      }
      for ($i = 0; $i <= $max; $i++) {
        $module = $field_types[$field['type']]['module'];
        $function = $module . '_content_generate';
        if (function_exists($function)) {
          $result = $function($node, $field);

          // $items, $teaser, $page
          if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {

            // Fields that handle their own multiples will add their own deltas.
            $node_field = $result;
          }
          else {

            // When multiples are handled by the content module, add a delta for each result.
            $node_field[$i] = $result;
          }
        }
      }
      $node->{$field['field_name']} = $node_field;
    }
  }
}