Feedback wanted on idea to improve menu weight in Node edit

behindthepage's picture

Often when I add a menu item for a node, using the menu settings on the node edit form, I have to go to the Menu Admin afterwards to drag the menu item into the correct place. This happens more often when there are lots of menu items.

My idea is to have a checkbox in the menu settings field group that if checked when the node is submitted the next page that is shown is the Menu Admin then when that is submitted you are tken back to the Node that you were originally editing.
Below is the module so far:

I have called it menu weight but maybe a better name would be menu workflow.
Maybe you have a better idea for it's name?

menu_weight.info

name = Menu Weight
description = Replaces the cumbersome menu weight select with a drag and drop AHAH system.
dependencies[] = menu
version = "6.x-1.0"
core = "6.x"

menu_weight.module

<?php
/*
* Implementation of hook_form_alter
*/
function menu_weight_form_alter(&$form, $form_state, $form_id) {

  // if node form
  if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {

    // may need to check if user has permision to admin menu
    $form['menu']['admin_flag'] = array(
      '#type' => 'checkbox',
      '#default_value' => 0,
      '#title' => t('Take me to the menu admin once I submit this node.'),
      '#description' => t('Once you have saved the menu admin config you will be brought back to this node.'),
    );
  }
}

/**
* Implementation of hook_nodeapi
*/
function menu_weight_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {

    // new node
    case 'insert':
    case 'update':
      // if menu title is not empty goto menu admin
      // TO DO: need to work out what is the parent menu
      // at the moment it works for top level menu items
      if ( ($node->menu['link_title'] != '') AND ($node->menu['admin_flag'])) {

        $path = 'admin/build/menu-customize/' . $node->menu['menu_name'];

        //Once menu admin is saved bring them back to the node
        $destination = 'destination=node/'.$node->nid;

        drupal_set_message('When you save this page you will be returned to the node you have just created.');

        drupal_goto($path , $destination);
      }
    break;
  }
}

Regards
Geoff

Login to post comments

This would break any modules

Dave Reid's picture
Dave Reid - Thu, 2009-11-19 15:15

This would break any modules that implement hook_nodeapi and have a higher weight that your module (or sorted alphabetically past your module's name). drupal_goto() causes an immediate redirect and stops all further execution of the current PHP request. You'd probably want to use something in a custom submit handler from the node form to adjust $form['#redirect'] or $form_state['redirect'].

Drupal freelance developer | www.davereid.net | Please help sponsor my attendance at DrupalCon SF 2010!