You are here

function nodehierarchy_form_alter in Node Hierarchy 6

Same name and namespace in other branches
  1. 5 nodehierarchy.module \nodehierarchy_form_alter()
  2. 6.3 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 183

Code

function nodehierarchy_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  switch ($form_id) {
    case 'node_type_form':
      $type = $form['old_type']['#value'];
      $form['nodehierarchy'] = array(
        '#type' => 'fieldset',
        '#title' => t('Node Hierarchy'),
        '#weight' => 10,
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $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 50.
      if (isset($form['menu']['weight']) && $form['menu']['weight']['#default_value'] > 50) {
        $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'] > 50) {
        $form['weight']['#delta'] = $form['weight']['#default_value'];
      }
      break;
    case 'node_delete_confirm':
      if ($count = _nodehierarchy_get_children_count($form['nid']['#value'])) {
        $description = format_plural($count, 'This node has @count child. Check this box to delete it and all of its descendants as well.', 'This node has @count children. Check this box to delete them and all of their descendants as well.');
        $form['nodehierarchy_delete_children'] = array(
          '#type' => 'checkbox',
          '#title' => t('Delete descendants'),
          '#description' => $description,
        );
        array_unshift($form['#submit'], 'nodehierarchy_node_delete_submit');
        $form['actions']['#weight'] = 1;
      }
      break;
  }
}