I'm having a crack at re-enabling menu support.
As I did exactly a year ago today (!) for D5.

It's working great - I'm just futzing with the user interface right now.
I tried basing it on path (cool) then figured out how to get it to use its own selector (after trial and error) ... then realized that it wouldn't work without path support anyway, so I'm about to take it back to path dependancy.
Here's a preview FYI anyway. Works, but some UI and code revision to go.
Should have a clean release by the end of the day.
Everything I did was by learning from example, so I don't truly grok the process - just did what seemed to be needed.

Not a patch - a drop-in replacement really.

CommentFileSizeAuthor
#17 menu.inc__2.txt5.86 KBstacysimpson
#4 menu.inc_.txt4.82 KBdman
menu.inc_.txt4.94 KBdman

Comments

Robrecht Jacques’s picture

Some comments:

  • I don't see any reason not to map "menu:weight". Although your "weight == order of import" is fine I suppose.
  •     // Not exactly sure what this does :-{
        node_import_set_object('menu:parent', $values['menu:parent'], $values['menu:path']);
    

    The node_import_set_object()/node_import_get_object() is a form of cache. It avoids looking up the same values (eg node title → node id). Whenever you have some db_query() it probably is useful to have a node_import_set_object(). What is stored in the cache is up to you, for example:

    node_import_set_object('user', 'some name', $uid);
    node_import_set_object('node', 'some title', $nid);
    

    It is also used to store (and retrieve) inverse lookups. Eg when a node is created it can do:

    node_import_set_object('node:title', $nid, 'some title');
    

    although I'm only using this in supported/book.inc right now which contains a lot of code to handle the case where you import a whole book. To avoid having errors that the parent book page (identified by title) does not exist, I have some $virtual_book_page counter. The reverse lookup is then used to inform the user that the book page will be created during import. supported/taxonomy.inc needs some rewriting to use the same logic. A lot of code which is just used in preview anyway :/

    So you probably want:

        if (($parent = node_import_get_object('menu:path', $values['menu:path'])) || ($parent = menu_node_import_get_parent_from_path($values['menu:path']) ))  {
          $values['menu:parent'] = $parent;
        }
        else {
          // otherwise drop it into the configured menu root.
          drupal_set_message("Failed to find an existing menu parent of ". $values['menu:path'] . " - just dropping it in the root of the menu.");
    //this doesn't do anything:      $values['menu:parent'] = $values['menu:parent'];
        }
    
        // Caching the parent will avoid looking it up the next time.
        node_import_set_object('menu:path', $values['menu:path'], $values['menu:parent']);
    

Looking forward to seeing this completed.

Robrecht Jacques’s picture

BTW: I think it is useful to look at supported/book.inc because the hierarchy of books is stored in the menu tables as well. So probably some parts can be reused.

And you will probably also need hook_node_import_postprocess() as well (same as in 5.x).

dman’s picture

Thanks for the review.
I consider it pretty unlikely that anyone will source an input file where the menu weight is supplied - or a list where source-order is not the assumed import order.
my attempt at ordering with 'static' failed (batch processing ;-) and wouldn't let me go over 50 either. I'll see if the cache object is the place to put that meta-counter(s).
To build the menu, I require that parent items be listed before children anyway.

And there's my current tweak remaining...

I futzed around a lot and found that a handful of items were not making it in. Turns out to be because the menu module caches things a little aggressively, and if a parent is made, then a child made immediately after, even though I bypass the cache to find the parent menu ID (this is working fine) the node_save form validation doesn't yet believe the parent exists... and bitches.
So I tried flushing the cache all the time... which was way too slow.
Leaving me with the last approach which is to check if the parent item is in the menu cache - and only if NOT - then flush the cache. :-{ Frustrating.
I guess that's why you built the cache thing. I'll see if it helps.

But anyway, in the course of this adventure I did get it to the point where I could import a hundred-page content map directly from the client Spec document... which is what it's all about. Although due to the above still-not-resolved-cleanly issue, I had to run the process twice. Code is still on the work dev machine this weekend ... I'll flick back the updated (tidier) one when I can.

dman’s picture

StatusFileSize
new4.82 KB

No actually, I did remember to take a snapshot.
Here it is. Shaped like the old one, but still very much a work-in-progress. (ie, partly broken with the menu cache issue)
Without reference (yet) to your tips above.

Robrecht Jacques’s picture

Well, I had the same problems in supported/book.inc :-)

You'll need to use the cache_set(), cache_get() for the weights as node_import_set/get() is on a request basis as well (just like static), so that will not work.

Book also complains about non-existing parents, so what I did was setting it in hook_node_import_postprocess().

There is also the "hidden feature" to set the global $node_import_can_continue to FALSE.

I'll have to look at it more closely this weekend as well.

feuillet’s picture

Hi,

I am exactly looking for something like this, to import nodes into menues.
Is this script working? If yes, how can it be used?

Best Regards
Sandro

Robrecht Jacques’s picture

You should copy the attachment in sites/all/modules/node_import/supported/menu.inc (or whereever you installed node_import module). Please test it and report back. I'll have time to look at it more closely next week.

feuillet’s picture

Hi Jaques,

Thanks for the hint, i can see now the mapping fields on the "Map file columns" Page.

Some things are not quiet clear now:

- What kind of data does the field "Parent path" expect?
- In the DB (table menu_links) i can see only a Value "plid" wich means to me "parent - link - id" wich is a reference to "mlid" in the same table.
- When i import a whole structure, this id is not known to me when i create the import document.

Would be great to have this cleared.

Thank you very much in advance.

Best Regards
Sandro

feuillet’s picture

One more thing, when i go further, after step 6 (Set default values) i get this error:

Fatal error: Call to undefined function dpm() in /www/htdocs/mysite/sites/all/modules/node_import/supported/menu.inc on line 119
feuillet’s picture

I forgot to mention, that i am using the dev release of node_import (6.x-1.x-dev (2009-Apr-22))
This because i have to import content in multiple languages and this is working only at the dev release.

Best Regards
Sandro

dman’s picture

oops. dpm() is my left-over.
Please just DELETE that line. dpm() is a debug line, and assumes you have devel.module.

... I seem to do that a lot. I leave scaffolding behind in development code :-}
'twas just a proof-of-concept at the time :-/

dman’s picture

re #8
Yes, internally the system need plid - and we don't know that yet.
So instead I make the ASSUMPTION that the alias path reflects the desired site structure. This is not always true of all sites, but is a good enough place to hinge upon for structured builds. The attached patch/contrib therefore does a lookup-by-string/path.

So, the parent path is a hierarchical path string.

about
about/people
about/people/director
about/people/developers
about/people/human-resources
about/contact
about/history

... is about as internally-consistent and self-explanatory as I could get.

Required: create the parent item before the child.

Anything more clever than this did not fit into a CSV format :-}

Suggestions for improvement welcome

feuillet’s picture

Thank you for the explanation, i know now what to do... :-)

Suggestions for improvement welcome

To solve the issue with the not known plids at the time of import, i can imagine to use something similar to the translation import id wich is a random number i write into the csv to make shure all translations are "attached" to the same node.

Example for translation:
Translation-ID, Title, Body, Node-Language
1, Homepage, Homepagebody in german, de
1, Page d'accuiel, Homepagebody in french, fr

We could use that ID/translation-number for the menu-import too:
To reflect a structure like:
Homepage
- About us
-- Contact
I would write a csv like:

Translation-ID, Title, Body, Node-Language, Menu-Parent (0=root), Menu-Name (as in the DB)
1, Homepage, Homepagebodycontent, de, 0, my-content-navigation
2, About us, About us content, de, 1 , my-content-navigation
3, Contact, Contact content, de, 2, my-content-navigation
and so on...

It would be required then to order the items inside import csv in a way, that the root documents are at the top and so on.

feuillet’s picture

So, the parent path is a hierarchical path string.

I assume the values of this path are the same as in the db field link_title (inside menu_links), right?

Robrecht Jacques’s picture

Translation-ID would be some kind of virtual NID to reference later to. I understand how this would work. Indeed for translations, this would be a logical way to go - never tackled that problem.

I prefer however to use something like the path. Compare it to how referencing users works: you rather use the email or name, rather then the UID. Don't know how if this could cleanly handle the translation as well.

If the first row creates a path like "/", row 2 could reference it as "/" (in your example), a sub-page of "About us" would reference the page as "/about-us". I think that is more clear. Menu and book should work the same, referencing by path (now node references are only referenced by title which doesn't always work). CCK Node references could profit from that as well. Instead of paths, there could be other ways to reference something else. Maybe a "virtual some id" would fit it.

dman worked on menu.inc, but indeed it was work-in-progress and only worked for his test/dev-site. I should clean it up... I should clean many things...

feuillet’s picture

now node references are only referenced by title

Ok, so if i understand that right, its the title field of the referenced node. This can contain special Characters and whitspaces...

Thank you, will try that.

stacysimpson’s picture

StatusFileSize
new5.86 KB

Started banging around a bit on this feature. We shifted things slightly to allow people to use the url alias for the node, which should be used as the parent menu item. Separated menu support from what looked like some logic based on the URL path for the inserted node itself.

Same deal...need to insert nodes level-by-level.

Robrecht Jacques’s picture

Version: 6.x-1.x-dev » 6.x-1.1
Status: Needs work » Needs review

Is this patch usuable?

I see I've disable the menu support... Would like to get it back in. I'll test...

Robrecht Jacques’s picture

Status: Needs review » Fixed

Committed to 6.x-1.x-dev. Will be included in next release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.