You are here

function content_instance_default_values in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 6 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 66
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_build_modes()));
  $widget['display_settings'] = array();
  foreach ($settings_names as $name) {
    $widget['display_settings'][$name]['format'] = $name == 'label' ? 'above' : 'default';
    $widget['display_settings'][$name]['exclude'] = 0;
  }

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