You are here

function nodehierarchy_form_alter in Node Hierarchy 6.3

Same name and namespace in other branches
  1. 5 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 214
A module to make nodes hierarchical.

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;
    case @$form['type']['#value'] . '_node_form':
      $node = isset($form['#node']) ? $form['#node'] : NULL;

      // Show core menu fieldset on node edit
      $menu_access = (bool) variable_get('nh_menu_display_core_' . $node->type, TRUE);
      $form['menu']['#access'] = $menu_access;

      // Breadcrumbs
      nodehierarchy_set_breadcrumbs($node, TRUE);
      $hierarchy_form = module_invoke_all('nodehierarchy_node_form', $node);

      // if the current user has no nodehierarchy perms, don't show the form
      $access = FALSE;
      foreach (nodehierarchy_perm() as $perm) {
        if (user_access($perm)) {
          $access = TRUE;
          break;
        }
      }

      // See if anything should actually be displayed in the fieldset. For the
      // time being, manually check 'menu_settings' also
      //
      // TODO: Potentially use a recursive function to look for a
      // user-selectable item? Seems a little overkill. Probably would be easier
      // to fix ['menu_settings']
      $nh_items = FALSE;
      $form_item_checks = array(
        @$hierarchy_form['nodehierarchy_menu_links'][0],
        @$hierarchy_form['nodehierarchy_menu_links'][0]['menu_settings'],
      );
      foreach ($form_item_checks as $form_item) {
        if (is_array($form_item)) {
          foreach ($form_item as $item) {
            if (is_array($item) && $item['#type'] && $item['#type'] != 'value') {
              $nh_items = TRUE;
              break 2;
            }
          }
        }
      }
      if ($nh_items === FALSE) {
        $access = FALSE;
      }
      if ($hierarchy_form) {
        $weight = function_exists('content_extra_field_weight') ? content_extra_field_weight($type, 'nodehierarchy') : 10;
        $form['nodehierarchy'] = array_merge(array(
          '#type' => 'fieldset',
          '#title' => t('Node Hierarchy'),
          '#collapsible' => TRUE,
          '#collapsed' => empty($form_state['nodehierarchy_expanded']) ? TRUE : FALSE,
          '#weight' => $weight,
          '#access' => $access,
        ), $hierarchy_form);
      }
      break;
    case 'node_delete_confirm':

      // TODO: Fix the descendant count code to deal with multiparent situations.
      if ($count = _nodehierarchy_get_children_count($form['nid']['#value'])) {
        $items = array();
        foreach (_nodehierarchy_get_children_menu_links($form['nid']['#value'], 10) as $child) {
          $items[] = check_plain($child['link_title']);
        }
        if ($count > 10) {
          $items[] = l(t('See all !count children', array(
            '!count' => $count,
          )), 'node/' . $form['nid']['#value'] . '/children');
        }
        $list = theme('item_list', $items);
        $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.');
        $description .= t('<p>These children and their decendants will be deleted:!list<p>', array(
          '!list' => $list,
        ));
        $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;
  }
}