hook_field_settings_form

7 field_ui.api.php hook_field_settings_form($field, $instance, $has_data)
8 field_ui.api.php hook_field_settings_form($field, $instance, $has_data)

Add settings to a field settings form.

Invoked from field_ui_field_settings_form() to allow the module defining the field to add global settings (i.e. settings that do not depend on the bundle or instance) to the field settings form. If the field already has data, only include settings that are safe to change.

@todo: Only the field type module knows which settings will affect the field's schema, but only the field storage module knows what schema changes are permitted once a field already has data. Probably we need an easy way for a field type module to ask whether an update to a new schema will be allowed without having to build up a fake $prior_field structure for hook_field_update_forbid().

Parameters

$field: The field structure being configured.

$instance: The instance structure being configured.

$has_data: TRUE if the field already has data, FALSE if not.

Return value

The form definition for the field settings.

Related topics

8 functions implement hook_field_settings_form()

2 invocations of hook_field_settings_form()

File

modules/field_ui/field_ui.api.php, line 38
Hooks provided by the Field UI module.

Code

function hook_field_settings_form($field, $instance, $has_data) {
  $settings = $field['settings'];
  $form['max_length'] = array(
    '#type' => 'textfield', 
    '#title' => t('Maximum length'), 
    '#default_value' => $settings['max_length'], 
    '#required' => FALSE, 
    '#element_validate' => array('element_validate_integer_positive'), 
    '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
  );
  return $form;
}

Comments

how to alter field settings

how to alter field settings form from another module ?

Use hook_from_alter

According to http://drupal.org/node/1308860 there is no special hook for altering settings form at the moment.

Note that if in

Note that if in hook_field_info() you have these settings:

function my_module_field_info(){
  return array(
    //...

    'settings' => array(
      'my_setting' => $default_value,
    ),
  );
}

Then, for drupal to save the data when the form is submited you MUST make the $form field-key the same as 'my_setting'.

function my_module_field_settings_form($field, $instance, $has_data) {
  // this WON'T work because the $form field-key is 'my_settings'
  // (note the 's') instead of  'my_setting'.
  $form['my_settings'] => array(
    '#type' => $type,
    '#title' => $title,
  );

  // this will work and the value will be stored.
  $form['my_setting'] => array(
    '#type' => $type,
    '#title' => $title,
  );
}

Login or register to post comments