function field_ui_default_value_widget

Builds the default value widget for a given field instance.

1 call to field_ui_default_value_widget()
field_ui_field_edit_form in drupal/core/modules/field_ui/field_ui.admin.inc
Form constructor for the field instance settings form.

File

drupal/core/modules/field_ui/field_ui.admin.inc, line 1021
Administrative interface for custom field type creation.

Code

function field_ui_default_value_widget($field, $instance, &$form, &$form_state) {
  $field_name = $field['field_name'];
  $entity = $form['#entity'];
  $element = array(
    '#type' => 'details',
    '#title' => t('Default value'),
    '#collapsible' => FALSE,
    '#tree' => TRUE,
    '#description' => t('The default value for this field, used when creating new content.'),
    // Stick to an empty 'parents' on this form in order not to breaks widgets
    // that do not use field_widget_[field|instance]() and still access
    // $form_state['field'] directly.
    '#parents' => array(),
  );

  // Adjust the instance definition used for the form element. We want a
  // non-required input and no description.
  $instance['required'] = FALSE;
  $instance['description'] = '';

  // Insert the widget. Since we do not use the "official" instance definition,
  // the whole flow cannot use field_invoke_method().
  $items = (array) $instance['default_value'];
  $element += $instance
    ->getWidget()
    ->form($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
  return $element;
}