You are here

function module_builder_node_form in Module Builder 6

1 string reference to 'module_builder_node_form'
module_builder_module_builder in ./module_builder.components.inc

File

./module_builder.components.inc, line 80

Code

function module_builder_node_form(&$form_state, $values) {
  if (isset($form_state['storage']['node_type_count']) && $form_state['storage']['node_type_count'] > 1 && isset($form_state['storage']['types']) && !empty($form_state['storage']['types'])) {
    $node_type_count = $form_state['storage']['node_type_count'];
    $types = $form_state['storage']['types'];
  }
  elseif (isset($values->types)) {
    $node_type_count = count($values->types);
    $types = $values->types;
  }
  else {
    $node_type_count = 1;
  }
  $default_type = array(
    'name' => '',
    'machine' => '',
    'description' => '',
    'locked' => FALSE,
  );
  $form = array(
    '#cache' => TRUE,
    '#tree' => TRUE,
  );
  $form['integration'] = array(
    '#type' => 'checkbox',
    '#title' => t('Integrate with the node module'),
    '#description' => t('If your module needs to interact with  node types other than the ones it defines, check this'),
    '#default_value' => isset($values->integration) ? (bool) $values->integration : FALSE,
  );
  $form['types'] = array(
    '#type' => 'fieldset',
    '#title' => t('Node types'),
    '#description' => t('If the module defines any node types, fill out these values.'),
    '#collapsible' => FALSE,
    '#prefix' => '<div id="node-types-wrapper">',
    '#suffix' => '</div>',
  );
  for ($delta = 0; $delta < $node_type_count; $delta++) {
    if (!isset($types[$delta])) {
      $type = $default_type;
    }
    else {
      $type = $types[$delta] + $default_type;
    }
    $form['types'][$delta] = array(
      '#type' => 'fieldset',
      '#title' => t('Node type'),
      // As an added bonus, change it to (!empty($type['name'])? $type['name'] : t('Node type'))
      '#collapsible' => TRUE,
    );
    $form['types'][$delta]['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#description' => t('The external (not machine-readable) name of the content type.'),
      '#default_value' => $type['name'],
    );
    $form['types'][$delta]['machine'] = array(
      '#type' => 'textfield',
      '#title' => t('Machine-readable name'),
      '#description' => t('The machine-readable name of the content type.'),
      '#default_value' => $type['machine'],
    );
    $form['types'][$delta]['description'] = array(
      '#type' => 'textfield',
      '#title' => t('Description'),
      '#description' => t('The description of the content type'),
      '#default_value' => $type['description'],
    );
    $form['types'][$delta]['locked'] = array(
      '#type' => 'checkbox',
      '#title' => t('Locked'),
      '#description' => t('If the content type is locked, the user can\'t modify any properties from the interface'),
      '#default_value' => $type['locked'],
    );
  }
  $form['types']['new'] = array(
    '#type' => 'submit',
    '#value' => t('New node type'),
    '#submit' => array(
      '_module_builder_node_submit',
    ),
    '#ahah' => array(
      'wrapper' => 'node-types-wrapper',
      'path' => 'module_builder/js',
    ),
  );
  $form['#pre_render'][] = 'module_builder_node_after_build';
  return $form;
}