function hook_field_settings_form

Add settings to a field settings form.

Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm 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

9 functions implement hook_field_settings_form()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

datetime_field_settings_form in drupal/core/modules/datetime/datetime.module
Implements hook_field_settings_form().
entity_reference_field_settings_form in drupal/core/modules/entity_reference/entity_reference.module
Implements hook_field_settings_form().
field_test_field_settings_form in drupal/core/modules/field/tests/modules/field_test/field_test.field.inc
Implements hook_field_settings_form().
file_field_settings_form in drupal/core/modules/file/file.field.inc
Implements hook_field_settings_form().
image_field_settings_form in drupal/core/modules/image/image.field.inc
Implements hook_field_settings_form().

... See full list

1 invocation of hook_field_settings_form()
FieldEditForm::buildForm in drupal/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php
Form constructor.

File

drupal/core/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' => 'number',
    '#title' => t('Maximum length'),
    '#default_value' => $settings['max_length'],
    '#required' => FALSE,
    '#min' => 1,
    '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
  );
  return $form;
}