You are here

function content_instance_default_values in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 includes/content.crud.inc \content_instance_default_values()
  2. 6.2 includes/content.crud.inc \content_instance_default_values()

Create an array of default values for a field instance.

1 call to content_instance_default_values()
content_field_instance_create in includes/content.crud.inc
Create a new field instance.

File

includes/content.crud.inc, line 67
Create/Read/Update/Delete functions for CCK-defined object types.

Code

function content_instance_default_values($field_name, $type_name, $widget_type) {
  $widget_types = _content_widget_types();
  $module = $widget_types[$widget_type]['module'];
  $widget = array(
    'field_name' => $field_name,
    'type_name' => $type_name,
    'weight' => 0,
    'label' => $field_name,
    'description' => '',
    'widget_type' => $widget_type,
    'widget_module' => $module,
    'display_settings' => array(),
    'widget_settings' => array(),
  );
  if (module_exists($module)) {
    $widget['widget_active'] = 1;
  }
  $settings_names = array_merge(array(
    'label',
  ), array_keys(_content_admin_display_contexts()));
  $widget['display_settings'] = array();
  foreach ($settings_names as $name) {
    $widget['display_settings'][$name]['format'] = $name == 'label' ? 'above' : 'default';
  }

  // Make sure widget settings all have an index in the array.
  $settings_names = module_invoke($module, 'widget_settings', 'save', $widget);
  $widget['widget_settings'] = array();
  foreach ((array) $settings_names as $name) {
    $widget['widget_settings'][$name] = NULL;
  }
  return $widget;
}