Community Documentation

CCK hook_default_value

Last updated February 26, 2009. Created by udioron on February 9, 2009.
Log in to edit this page.

<?php
/**
* sets default values for the field.
*
* To get this hook actually called, make sure to set
*   'default value' => CONTENT_CALLBACK_CUSTOM
* on hook_widget_info.
*/
function hook_default_value(&$form, &$form_state, $field, $delta) {

 
$items = array();
 
$field_name = $field['field_name'];

  switch (
$field['multiple']) {
    case
0:
     
$max = 1;
      break;
    case
1:
     
$max =  isset($form_state['item_count'][$field_name]) ? $form_state['item_count'][$field_name] : 1;
      break;
    default:
     
$max = $field['multiple'];
      break;
  }

  for (
$delta = 0; $delta < $max; $delta++) {
   
$items[$delta] = array(
     
/* YOUR STUFF HERE */
    
);
  }
  return
$items;
}
?>

This hook is called from content_field_form (content.node_form.inc)

Page status

About this page

Drupal version
Drupal 6.x

Structure Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here