You are here

function nd_fields in Node displays 6

Fields overview.

Parameters

string $node_type The node type.:

8 string references to 'nd_fields'
nd_block_field_form_submit in includes/nd.fields.inc
Save block field.
nd_block_field_form_validate in includes/nd.fields.inc
Validate block field submission, only on insert.
nd_code_field_form_submit in includes/nd.fields.inc
Save code field.
nd_code_field_form_validate in includes/nd.fields.inc
Validate code field submission, only on insert.
nd_field_delete_form_submit in includes/nd.fields.inc
Delete field.

... See full list

File

includes/nd.fields.inc, line 13
Manage fields.

Code

function nd_fields() {
  $output = '';
  $action = arg(5);
  $field = arg(6);

  // Get fields.
  $db_fields = variable_get('nd_fields', array());
  $all_fields = nd_get_fields(NULL, NULL, NULL);
  foreach ($all_fields as $key => $db_field) {
    if ($db_field['type'] == ND_FIELD_OVERRIDABLE && !isset($db_field[$key])) {
      $db_fields[$key] = array(
        'title' => $db_field['title'],
        'code' => $db_field['code'],
        'type' => $db_field['type'],
        'exclude' => isset($db_field['exclude']) ? $db_field['exclude'] : array(),
      );
    }
  }

  // Delete form.
  if (in_array($field, array_keys($db_fields)) && $action == 'delete') {
    $output .= drupal_get_form('nd_field_delete_form', $field, $db_fields[$field]);
  }
  elseif (in_array($field, array_keys($db_fields)) && $action == 'edit') {
    $form_id = $db_fields[$field]['type'] == ND_FIELD_BLOCK ? 'nd_block_field_form' : 'nd_code_field_form';
    $output .= drupal_get_form($form_id, $field, $db_fields[$field]);
  }
  else {
    if (empty($db_fields)) {
      $output .= '<p>' . t('You have not defined any custom fields.') . '</p>';
    }
    else {
      $header = array(
        t('Title'),
        t('Key'),
        t('Type'),
        t('Operations'),
      );
      $rows = array();
      foreach ($db_fields as $key => $value) {
        $row = array();
        $row[] = check_plain($value['title']);
        $row[] = $key;
        $type = $value['type'] == ND_FIELD_OVERRIDABLE ? t('Default') : ($value['type'] == ND_FIELD_OVERRIDDEN ? t('Overridden') : t('Custom'));
        if ($value['type'] == ND_FIELD_BLOCK) {
          $type = t('Block field');
        }
        $row[] = $type;
        $operations = l(t('Edit'), 'admin/content/types/nd/fields/edit/' . $key);
        if ($value['type'] != ND_FIELD_OVERRIDABLE) {
          $text = $value['type'] == ND_FIELD_OVERRIDDEN ? 'Reset' : 'Delete';
          $operations .= ' - ' . l(t($text), 'admin/content/types/nd/fields/delete/' . $key);
        }
        $row[] = $operations;
        $rows[] = $row;
      }
      $output .= theme('table', $header, $rows);
    }

    // New fields form.
    $output .= drupal_get_form('nd_code_field_form');
    $output .= drupal_get_form('nd_block_field_form');
  }
  return $output;
}