1 field_ui.admin.inc field_ui_view_mode_form($form, &$form_state, $entity_type = NULL, $bundle = NULL, $machine_name = NULL)

Form builder: Add or edit a display mode name.

File

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

Code

function field_ui_view_mode_form($form, &$form_state, $entity_type = NULL, $bundle = NULL, $machine_name = NULL) {
  $entity_info = entity_get_info($entity_type);
  $bundle = field_extract_bundle($entity_type, $bundle);
  $path = _field_ui_bundle_admin_path($entity_type, $bundle) . '/display';

  $form['#entity_info'] = $entity_info;
  $form['#entity_type'] = $entity_type;
  $form['#bundle'] = $bundle;
  $form['#path'] = $path;
  $form['#new'] = TRUE;

  if ($machine_name != NULL) {
    $view_mode = entity_view_mode_load($entity_type, $machine_name);
    $form['#new'] = FALSE;
  }

  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Display mode label'),
    '#default_value' => isset($view_mode['label']) ? $view_mode['label'] : '',
    '#size' => 20,
    '#states' => array(
      'visible' => array(
        ':input[name="existing"]' => array('value' => 'new'),
      ),
    ),
  );

  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#title' => t('Machine name'),
    '#default_value' => $machine_name,
    '#entity_type' => $entity_type,
    '#maxlength' => 26,
    '#required' => FALSE,
    '#description' => t('A unique machine-readable name containing letters, numbers, and underscores.'),
    '#size' => 15,
    '#machine_name' => array(
      'source' => array('label'),
      'exists' => 'entity_view_mode_exists',
    ),
  );
  if (!$form['#new']) {
    // Cannot change existing machine names.
    $form['machine_name']['#disabled'] = TRUE;
  }

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'markup',
    '#markup' => l(t('Cancel'), $path),
  );

  return $form;
}