You are here

function nd_code_field_form in Node displays 6

Code field form.

Parameters

string $key The key of the field.:

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

1 string reference to 'nd_code_field_form'
nd_fields in includes/nd.fields.inc
Fields overview.

File

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

Code

function nd_code_field_form($form_state, $key = '', $field = array()) {
  $form = array();
  if (empty($field)) {
    $field = array(
      'title' => '',
      'code' => '',
      'exclude' => array(),
      'type' => ND_FIELD_CUSTOM,
    );
  }
  $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 field.');
  }
  $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'],
  );
  $ctypes = node_get_types('names');
  $form['code_identity']['code_exclude'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Field exclude'),
    '#options' => $ctypes,
    '#description' => t('Toggle content types which you don\'t want the field to appear in.'),
    '#default_value' => $field['exclude'],
  );
  $form['code_identity']['code_code'] = array(
    '#type' => 'textarea',
    '#title' => t('Field code'),
    '#required' => TRUE,
    '#default_value' => $field['code'],
  );
  _nd_field_node_info($form);
  $form['code_identity']['code_submit'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'nd_code_field_form_submit',
    ),
    '#value' => t('Save code field'),
  );
  $form['#field_type'] = $field['type'] == ND_FIELD_OVERRIDABLE ? ND_FIELD_OVERRIDDEN : ($field['type'] == ND_FIELD_OVERRIDDEN ? ND_FIELD_OVERRIDDEN : ND_FIELD_CUSTOM);
  $form['#form_type'] = empty($key) ? 'insert' : 'update';
  return $form;
}