field_ui_field_settings_form

Versions
7
field_ui_field_settings_form($form, &$form_state, $obj_type, $bundle, $instance)

Menu callback; presents the field settings edit page.

Code

modules/field_ui/field_ui.admin.inc, line 807

<?php
function field_ui_field_settings_form($form, &$form_state, $obj_type, $bundle, $instance) {
  $bundle = field_extract_bundle($obj_type, $bundle);
  $field = field_info_field($instance['field_name']);

  // When a field is first created, we have to get data from the db.
  if (!isset($instance['label'])) {
    $instance = field_read_instance($field['field_name'], $bundle);
    $field = field_read_field($field['field_name']);
  }

  drupal_set_title($instance['label']);

  $description = '<p>' . t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $instance['label'])) . '</p>';

  // Create a form structure for the field values.
  $form['field'] = array(
    '#type' => 'fieldset',
    '#title' => t('Field settings'),
    '#description' => $description,
    '#tree' => TRUE,
  );

  // See if data already exists for this field.
  // If so, prevent changes to the field settings.
  $has_data = field_has_data($field);
  if ($has_data) {
    $form['field']['#description'] = '<div class=error>' . t('There is data for this field in the database. The field settings can no longer be changed.' . '</div>') . $form['field']['#description'];
  }

  // Build the non-configurable field values.
  $form['field']['field_name'] = array('#type' => 'value', '#value' => $field['field_name']);
  $form['field']['type'] = array('#type' => 'value', '#value' => $field['type']);
  $form['field']['module'] = array('#type' => 'value', '#value' => $field['module']);
  $form['field']['active'] = array('#type' => 'value', '#value' => $field['active']);

  // Set translatability.
  $form['field']['translatable'] = array(
    '#type' => 'radios',
    '#title' => t('Multilingual settings'),
    '#options' => array(TRUE => t('Translatable field'), FALSE => t('Language neutral field')),
    '#default_value' => $field['translatable'],
    '#description' => t("Translatable fields can have a different value for each available language. An example of a translatable field is an article's <em>body</em>. Language neutral fields will retain the same value across all translations. An example of a language neutral field is a user profile's <em>first name</em>."),
  );

  // Add settings provided by the field module. The field module is
  // responsible for not returning settings that cannot be changed if
  // the field already has data.
  $form['field']['settings'] = array();
  $additions = module_invoke($field['module'], 'field_settings_form', $field, $instance, $has_data);
  if (is_array($additions)) {
    $form['field']['settings'] = $additions;
  }
  if (empty($form['field']['settings'])) {
    $form['field']['settings'] = array(
      '#markup' => t('%field has no field settings.', array('%field' => $instance['label'])),
    );
  }
  $form['#object_type'] = $obj_type;
  $form['#bundle'] = $bundle;

  $form['submit'] = array('#type' => 'submit', '#value' => t('Save field settings'));
  return $form;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.