You are here

function _node_field_node_field_page_new_field_form in Node Field 7.2

Form element for new node field.

1 call to _node_field_node_field_page_new_field_form()
node_field_node_field_form in includes/node_field.form.node_field.inc
Node field form.

File

includes/node_field.form.node_field.inc, line 157
Node fields forms.

Code

function _node_field_node_field_page_new_field_form(&$form, $form_state) {

  // Building new field form.
  $form['node_fields']['new'] = [
    '#tree' => TRUE,
  ];
  $form['node_fields']['new']['title'] = [
    '#type' => 'textfield',
    '#title' => t('Add new field'),
    '#description' => t('Label'),
  ];
  $delta_max = ceil(count($form_state['node_fields']) / 2);
  if (!empty($form_state['node_fields'])) {
    foreach ($form_state['node_fields'] as $node_field) {
      $delta_max = max($delta_max, abs($node_field['weight']));
    }
  }
  $form['node_fields']['new']['weight'] = [
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#title_display' => 'invisible',
    '#default_value' => $delta_max,
    '#delta' => $delta_max,
  ];
  $form['node_fields']['new']['type'] = [
    '#type' => 'select',
    '#title' => t('Type'),
    '#title_display' => 'invisible',
    '#description' => t('Field type'),
    '#options' => node_field_node_field_types_options(),
  ];
  $form['node_fields']['new']['machine_name'] = [
    '#type' => 'machine_name',
    '#title' => t('Machine name'),
    '#description' => t('It must only contain lowercase letters, numbers and hyphens.'),
    '#maxlength' => 256,
    '#required' => FALSE,
    '#machine_name' => [
      'exists' => 'node_field_machine_name_check',
      'source' => [
        'node_fields',
        'new',
        'title',
      ],
    ],
  ];
}