You are here

function ds_fields in Display Suite 6.2

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

Fields overview.

2 string references to 'ds_fields'
ds_layout_overview in includes/ds.display.inc
General overview page.
_ds_ui_menu in includes/ds.registry.inc
Return menu items and import default settings.

File

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

Code

function ds_fields($module) {
  $output = '';
  $action = check_plain(arg(6));
  $field = check_plain(arg(7));
  drupal_add_js(drupal_get_path('module', 'ds') . '/js/fields.js');

  // Get API information.
  $api_info = ds_api_info($module);

  // Extra info.
  $extra = array();

  // Get fields.
  $db_fields = variable_get($module . '_fields', array());
  $all_fields = ds_get_fields($module, NULL, NULL, $extra, TRUE);

  // Compare with db_fields.
  foreach ($all_fields as $key => $ds_field) {
    if ($ds_field['status'] == DS_FIELD_STATUS_DEFAULT && !isset($db_fields[$key])) {
      $db_fields[$key] = array(
        'title' => $ds_field['title'],
        'properties' => $ds_field['properties'],
        'type' => $ds_field['type'],
        'status' => $ds_field['status'],
        'exclude' => isset($ds_field['exclude']) ? $ds_field['exclude'] : array(),
      );
    }
  }

  // Delete form.
  if (in_array($field, array_keys($db_fields)) && $action == 'delete') {
    $output .= drupal_get_form('ds_field_delete_reset_form', $module, $field, $db_fields[$field]);
  }
  elseif (in_array($field, array_keys($db_fields)) && $action == 'edit') {
    if ($db_fields[$field]['type'] == DS_FIELD_TYPE_BLOCK) {
      $form_id = 'ds_block_field_form';
    }
    elseif ($db_fields[$field]['type'] == DS_FIELD_TYPE_PREPROCESS) {
      $form_id = 'ds_preprocess_field_form';
    }
    else {
      $form_id = 'ds_code_field_form';
    }
    $output .= drupal_get_form($form_id, $module, $all_fields, $api_info['object'], $field, $db_fields[$field]);
  }
  else {
    $rows = array();
    foreach ($db_fields as $key => $value) {
      if ($value['type'] != DS_FIELD_TYPE_GROUP) {
        $row = array();
        $row[] = l($value['title'], DS_PATH_MODULES . '/' . $module . '/fields/edit/' . $key);
        $row[] = $key;
        $row[] = ds_human_name($value['type'], 'type');
        $row[] = ds_human_name($value['status'], 'status');
        $operations = l(t('Edit'), DS_PATH_MODULES . '/' . $module . '/fields/edit/' . $key);
        if ($value['status'] != DS_FIELD_STATUS_DEFAULT) {
          $text = $value['status'] == DS_FIELD_STATUS_OVERRIDDEN ? 'Reset' : 'Delete';
          $operations .= ' - ' . l(t($text), DS_PATH_MODULES . '/' . $module . '/fields/delete/' . $key);
        }
        $row[] = $operations;
        $rows[] = $row;
      }
    }
    if (!empty($rows)) {
      $header = array(
        t('Title'),
        t('Key'),
        t('Type'),
        t('Status'),
        t('Operations'),
      );
      $output .= '<p>' . t('This is a list of fields either defined in code or via the UI.') . ' ';
      if (!isset($api_info['no_fields_examples'])) {
        $output .= t('You can look at <a href="javascript:;" onClick="window.open(\'!url\', \'mywindow\', \'width=800,height=600,scrollbars=yes,location=1,resizable=1,toolbar=1\'); return false();">properties and preprocess variables</a> for any object type in a separate window.', array(
          '!url' => url(DS_PATH_MODULES . '/' . $module . '/fields-examples'),
        )) . '</p>';
      }
      $output .= theme('table', $header, $rows);
    }
    else {
      $output .= '<p>' . t('You have not defined any fields.') . ' ';
      if (!isset($api_info['no_fields_examples'])) {
        $output .= t('You can look at <a href="javascript:;" onClick="window.open(\'!url\', \'mywindow\', \'width=800,height=600,scrollbars=yes,location=1,resizable=1,toolbar=1\'); return false();">properties and preprocess variables</a> for any object type in a separate window.', array(
          '!url' => url(DS_PATH_MODULES . '/' . $module . '/fields-examples'),
        )) . '</p>';
      }
    }

    // New code field form.
    $output .= drupal_get_form('ds_code_field_form', $module, $all_fields, $api_info['object']);

    // New preprocess field form.
    $output .= drupal_get_form('ds_preprocess_field_form', $module, $all_fields, $api_info['object']);

    // Block field form.
    $output .= drupal_get_form('ds_block_field_form', $module, $all_fields);
  }
  return $output;
}