You are here

function ds_code_field_form in Display Suite 6.2

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

Code 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_code_field_form'
ds_fields in includes/ds.fields.inc
Fields overview.

File

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

Code

function ds_code_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_CODE,
      'status' => DS_FIELD_STATUS_CUSTOM,
      'properties' => array(
        'code' => '',
        'css-class' => '',
        'token' => FALSE,
      ),
    );
  }
  $form['code_identity'] = array(
    '#type' => 'fieldset',
    '#title' => empty($key) ? t('Add new code field') : t('Update code field'),
    '#collapsible' => empty($key) ? TRUE : FALSE,
    '#collapsed' => empty($key) ? TRUE : FALSE,
  );
  $form['code_identity']['code_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Field key'),
    '#description' => t('The machine-readable name of this field.'),
    '#required' => TRUE,
  );
  if (!empty($key)) {
    $form['code_identity']['code_key']['#disabled'] = TRUE;
    $form['code_identity']['code_key']['#value'] = $key;
    $form['code_identity']['code_key']['#description'] = t('The machine-readable name of this field. Note: you can not edit this key.');
  }
  $form['code_identity']['code_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['code_identity']['code_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) {

      // Views displays is special case.
      if ($module == 'vd') {
        $global_exclude = variable_get($module . '_type_' . $tkey, FALSE);
        if ($global_exclude == TRUE) {
          continue;
        }
      }
      $types[$tkey] = check_plain($type->name);
    }
    $form['code_identity']['code_exclude'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Field exclude'),
      '#options' => $types,
      '#default_value' => $field['exclude'],
      '#attributes' => array(
        'class' => 'exclude-types',
      ),
    );
    $form['code_identity']['code_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['code_identity']['code_exclude'] = array(
      '#type' => 'value',
      '#value' => array(),
    );
  }
  $form['code_identity']['code_code'] = array(
    '#type' => 'textarea',
    '#title' => t('Field code'),
    '#required' => TRUE,
    '#default_value' => $field['properties']['code'],
  );
  _ds_field_object_info($form, $object, $field);
  $form['code_identity']['code_submit'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'ds_code_field_form_submit',
    ),
    '#value' => t('Save code 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;
}