You are here

function nodehierarchy_form_alter in Node Hierarchy 5

Same name and namespace in other branches
  1. 6.3 nodehierarchy.module \nodehierarchy_form_alter()
  2. 6 nodehierarchy.module \nodehierarchy_form_alter()
  3. 6.2 nodehierarchy.module \nodehierarchy_form_alter()
  4. 7.4 nodehierarchy.module \nodehierarchy_form_alter()
  5. 7.2 nodehierarchy.module \nodehierarchy_form_alter()

Implementation of hooks_form_alter().

So we don't see preview or delete buttons for hierarchy.

File

./nodehierarchy.module, line 166
A module to make nodes hierarchical.

Code

function nodehierarchy_form_alter($form_id, &$form) {
  global $user;
  switch ($form_id) {
    case 'node_type_form':
      $type = $form['old_type']['#value'];
      $form['nodehierarchy'] = array(
        '#type' => 'fieldset',
        '#title' => t('Node Hierarchy'),
        '#weight' => 0,
      );
      $form['nodehierarchy'] += _nodehierarchy_get_node_type_settings_form($type);
      break;

    // Node edit form.
    case $form['type']['#value'] . '_node_form':
      $node = isset($form['#node']) ? $form['#node'] : NULL;
      $hierarchy_form = nodehierarchy_invoke_api("node_form", $node);
      if ($hierarchy_form) {
        $form['hierarchy'] = $hierarchy_form;

        // If there are any visible elements, wrap them in a fieldset.
        foreach ($hierarchy_form as $item) {
          if ($item['#type'] !== "value" && $item['#type'] !== "hidden") {
            $form['hierarchy'] = array_merge(array(
              '#type' => 'fieldset',
              '#title' => t('Node Hierarchy'),
              '#collapsible' => TRUE,
              '#collapsed' => TRUE,
            ), $form['hierarchy']);
            break;
          }
        }
      }

      // Allow for menu weights greater than 10, as is often the case with large hierarchies.
      if (isset($form['menu']['weight']) && $form['menu']['weight']['#default_value'] > 10) {
        $form['menu']['weight']['#delta'] = $form['menu']['weight']['#default_value'];
      }
      break;
    case 'menu_edit_item_form':

      // Allow for menu weights greater than 10, as is often the case with large hierarchies.
      if (isset($form['weight']) && $form['weight']['#default_value'] > 10) {
        $form['weight']['#delta'] = $form['weight']['#default_value'];
      }
      break;
    case 'node_delete_confirm':
      if ($count = _nodehierarchy_get_children_count($form['nid']['#value'])) {
        $form['nodehierarchy_delete_children'] = array(
          '#type' => 'checkbox',
          '#title' => t('Delete children'),
          '#description' => format_plural($count, 'This node has @count child. Check this box to delete it as well.', 'This node has @count children. Check this box to delete them as well.'),
        );
        $form['#submit'] = array(
          'nodehierarchy_node_delete_submit' => '',
        ) + $form['#submit'];
        $form['actions']['#weight'] = 1;
      }
      break;
  }
}