Cool, this is working exactly like I want it.

I've just added an extension for menu support! - based on the assumption that structured values in a 'path' imply actual structure.

This works just fine, but now I can't see how to turn it off :-)
When this supported/menu.inc file is present ... it just goes, but I cannot find where in the import wizard I should add a setting to disable it, or to define the root menu it builds the files under.

Now this is a cool tool for fast prototyping a sitemap for me!

sample content spreadsheet

Path Title
home Home
about About Us
products Product overview
products/consumables Consumables
products/rigging Rigging
products/effects Stunt Gear and Special Effects
products/workshop Workshop
products/vehicles Vehicles
products/vehicles/truck-a Truck A
products/vehicles/truck-b Truck B

Comments

Robrecht Jacques’s picture

Woah, extremely useful.

If I understand it correctly, you deduce the menu from $node->path. This means the user needs to assign a column from the CSV file to path (see supported/path.inc). I think it is better to make a seperate field for it:

/**
 * Implementation of hook_node_import_fields().
 */
function menu_node_import_fields() {
  return array(
    'node_import_menu' => t('Menu: menu path'),
  );
}

Then in menu_node_import_postprocess() use $node->node_import_menu instead of $node->path. This way one can disable the feature (by not mapping the "Menu: menu path" field to any column) and it becomes possible to have a different menu path and normal path.

Your other problem is how to specify the menu the stuff is built under. You would need to implement some menu_node_import_global() for that which returns a form. If you need some help with that, tell me.

The code itself looks good, except for the messages. Eg:

      drupal_set_message("No parent menu '$parent_system_path' - '$parent_path' - cannot make a menu entry for the page $node->path");

should be:

      drupal_set_message(t('No parent menu %parent_system_path - %parent_path - cannot make a menu entry for the page %node_path', array('%parent_system_path' => $parent_system_path, '%parent_path' => $parent_path, '%node_path' => $node->path)));

this way strings can be translated AND you avoid injecting stuff into the messages.

Also:

  $node->menu = array(
    'path' => 'node/' . $node->nid,
    'title' => $node->title,
    'pid' => $pid,
    'weight' => $menu_weight,
    'type' => 118,
  );

This 118 should be some combination of constants instead of a number.

I did not test it fully, but if you can work on it a bit more, it's likely to get included.

If you can't work on it anymore, please tell me.

dman’s picture

Mmm,
I do assume that the URL structure of my websites should reflect the menu navigation path. And vice versa. I just find that the most sensible, and actually think that deliberately breaking that convention by having URLs imply one thing and the menus built differently would be a gross architectural mistake.

I see what you are suggesting with adding a whole 'nother column, and that would enable me to turn this feature on and off by not using it ... But I was just trying to find the right place in the UI (2 1/2 months ago) to insert a checkbox :-)

Yeah, I was a bit lazy with a t() somewhere. That happens in prototype code.

I don't think I actually deciphered what that menu number means :-} so I'm not sure of the constants. I just copied it out of my database after a few failed attempts to guess the right constants.

I'm still unsure how you suggest to present a menu selector to choose the root. I couldn't figure the hook or callback.

What I've done so far is
- Manually create one menu - either a root or placed somewhere - and named it with an alias.
- Then I run an import with my paths starting with that alias. The system finds the parent menu and proceeds to build the children off there.

This works perfectly for me, but is a slightly obscure process for users I guess.

If I was to add the user selector, we'd also have to have a 'create new menu item' option etc.
I just didn't at the time because I couldn't find a way to hook into the process at the right time - how to alter the form or something - from the include file.

I've got work on at the moment, and am way past the prototype I needed this for. But I'm still developing lots of stuff with import/export so I'll probably revisit this tool again eventually.
... but just not in a hurry right now, sorry.

Robrecht Jacques’s picture

Understood. I'll look into it later myself. Menu == path makes sense.

Robrecht Jacques’s picture

Status: Needs work » Closed (won't fix)

5.x-1.x is no longer supported. Menu support has been added to 6.x-1.x.