You are here

function ds_preprocess_field_form in Display Suite 6.3

Same name and namespace in other branches
  1. 6 includes/ds.fields.inc \ds_preprocess_field_form()
  2. 6.2 includes/ds.fields.inc \ds_preprocess_field_form()

Preprocess field form.

Parameters

string $module The module the field is for.:

array $all_fields All fields for this module.:

string $object The object name (ie node, user, comment).:

string $key The key of the field.:

array $field The field with title and code keys.:

1 string reference to 'ds_preprocess_field_form'
ds_fields in includes/ds.fields.inc
Fields overview.

File

includes/ds.fields.inc, line 344
Manage fields.

Code

function ds_preprocess_field_form($form_state, $module, $all_fields, $object = '', $key = '', $field = array()) {
  $form = array();
  if (empty($field)) {
    $field = array(
      'title' => '',
      'exclude' => array(),
      'type' => DS_FIELD_TYPE_PREPROCESS,
      'status' => DS_FIELD_STATUS_CUSTOM,
      'properties' => array(
        'key' => '',
        'css-class' => '',
      ),
    );
  }
  $form['preprocess_identity'] = array(
    '#type' => 'fieldset',
    '#title' => empty($key) ? t('Add new preprocess field') : t('Update preprocess field'),
    '#description' => t('Create fields from variables available when preprocessing an object. For inspiration, see <a href="!url">!url</a>.', array(
      '!url' => 'http://drupal.org/node/700056',
    )),
    '#collapsible' => empty($key) ? TRUE : FALSE,
    '#collapsed' => empty($key) ? TRUE : FALSE,
  );
  $form['preprocess_identity']['preprocess_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Field key'),
    '#description' => t('The machine-readable name of this field. This is also the key that DS is searching in the $vars variable.'),
    '#required' => TRUE,
  );
  if (!empty($key)) {
    $form['preprocess_identity']['preprocess_key']['#disabled'] = TRUE;
    $form['preprocess_identity']['preprocess_key']['#value'] = $key;
    $form['preprocess_identity']['preprocess_key']['#description'] = t('The machine-readable name of this field. Note: you can not edit this key.');
  }
  $form['preprocess_identity']['preprocess_array_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Variable key'),
    '#required' => FALSE,
    '#description' => t('Enter a key if the variable is an array. Eg: og_links is an array and the display in that variable is available in the key "view"'),
    '#default_value' => $field['properties']['key'],
  );
  $form['preprocess_identity']['preprocess_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Field title'),
    '#description' => t('The title to use when rendering the output and on the display administration screen.'),
    '#required' => TRUE,
    '#default_value' => $field['title'],
  );
  $form['preprocess_identity']['preprocess_class'] = array(
    '#type' => 'textfield',
    '#title' => t('Field class'),
    '#description' => t('The classes you want to add to this field. This will replace the automatic class that Display Suite generates.'),
    '#default_value' => isset($field['properties']['css-class']) ? $field['properties']['css-class'] : '',
  );
  $api_info = ds_api_info($module);
  if (isset($api_info['types']) && count($api_info['types']()) > 1) {
    $types = array();
    foreach ($api_info['types']() as $tkey => $type) {
      $types[$tkey] = check_plain($type->name);
    }
    $form['preprocess_identity']['preprocess_exclude'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Field exclude'),
      '#options' => $types,
      '#default_value' => $field['exclude'],
      '#attributes' => array(
        'class' => 'exclude-types',
      ),
    );
    $form['preprocess_identity']['preprocess_exclude_all'] = array(
      '#type' => 'checkbox',
      '#title' => t('Select all'),
      '#description' => t('Toggle types which you don\'t want the field to appear in.'),
      '#attributes' => array(
        'class' => 'select-all',
      ),
    );
  }
  else {
    $form['preprocess_identity']['preprocess_exclude'] = array(
      '#type' => 'value',
      '#value' => array(),
    );
  }
  $form['preprocess_identity']['preprocess_submit'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'ds_preprocess_field_form_submit',
    ),
    '#value' => t('Save preprocess field'),
  );
  $form['#field_status'] = $field['status'] == DS_FIELD_STATUS_DEFAULT ? DS_FIELD_STATUS_OVERRIDDEN : ($field['type'] == DS_FIELD_STATUS_OVERRIDDEN ? DS_FIELD_STATUS_OVERRIDDEN : DS_FIELD_STATUS_CUSTOM);
  $form['#form_type'] = empty($key) ? 'insert' : 'update';
  $form['#module'] = $module;
  $form['#all_fields'] = $all_fields;
  return $form;
}