You are here

function ds_shared_form in Display Suite 7.2

Same name and namespace in other branches
  1. 7 ds.fields.inc \ds_shared_form()

Shared form for all fields.

4 calls to ds_shared_form()
ds_edit_block_field_form in modules/ds_ui/includes/ds.fields.inc
Manage a custom block.
ds_edit_ctools_field_form in modules/ds_ui/includes/ds.fields.inc
Manage a CTools field.
ds_edit_custom_field_form in modules/ds_ui/includes/ds.fields.inc
Manage a custom field.
ds_edit_preprocess_field_form in modules/ds_ui/includes/ds.fields.inc
Manage a Preprocess field.

File

modules/ds_ui/includes/ds.fields.inc, line 119
Administrative functions for managing custom fields for every entity.

Code

function ds_shared_form(&$form, $field) {
  ctools_include('export');
  $custom_fields = ctools_export_crud_load_all('ds_fields');
  if (isset($custom_fields[$field])) {
    $field = $custom_fields[$field];
    if (!isset($field->ui_limit)) {
      $field->ui_limit = '';
    }
  }
  else {
    $field = new stdClass();
    $field->label = '';
    $field->field = '';
    $field->ui_limit = '';
    $field->entities = array();
    $field->properties = array();
  }
  $form['name'] = array(
    '#title' => t('Label'),
    '#type' => 'textfield',
    '#default_value' => $field->label,
    '#description' => t('The human-readable label of the field.'),
    '#maxlength' => 128,
    '#required' => TRUE,
    '#size' => 30,
  );
  $form['field'] = array(
    '#type' => 'machine_name',
    '#default_value' => $field->field,
    '#maxlength' => 32,
    '#description' => t('The machine-readable name of this field. This name must contain only lowercase letters and underscores. This name must be unique.'),
    '#disabled' => !empty($field->field),
    '#machine_name' => array(
      'exists' => 'ds_field_unique',
    ),
  );
  $entity_options = array();
  $entities = entity_get_info();
  foreach ($entities as $entity_type => $entity_info) {
    if (isset($entity_info['fieldable']) && $entity_info['fieldable'] || $entity_type == 'ds_views') {
      $entity_options[$entity_type] = drupal_ucfirst(str_replace('_', ' ', $entity_type));
    }
  }
  $form['entities'] = array(
    '#title' => t('Entities'),
    '#description' => t('Select the entities for which this field will be made available.'),
    '#type' => 'checkboxes',
    '#required' => TRUE,
    '#options' => $entity_options,
    '#default_value' => $field->entities,
  );
  $form['ui_limit'] = array(
    '#title' => t('Limit field'),
    '#description' => t('Limit this field on field UI per bundles and/or view modes. The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'. You may use * to select all, e.g article|*, *|full or *|*. Enter one value per line.'),
    '#type' => 'textarea',
    '#default_value' => $field->ui_limit,
    '#element_validate' => array(
      'ds_ui_limit_validate',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 100,
  );

  // Validate & submit are also the same.
  $form['#validate'][] = 'ds_shared_form_validate';
  $form['#submit'][] = 'ds_shared_form_submit';
  return $field;
}