Hello,

Following, is a simple patch that adds a menu item mapping target to the node processor. The patch requires the system menu name only. I realize that this could go much further (many options to consider), but before assuming too much I thought I might read a few comments.

Cheers

Comments

nlambert’s picture

StatusFileSize
new1.79 KB

the patch

pindaman’s picture

HI,
How does it work
I have a field i want to use as menu item.
eg. menu main-menu
parent-item:apples
child item: green

is it meant for such solution?
Without doc i am a bit lost :(

pinda

nlambert’s picture

You must map your csv column to the "Menu Name" mapper in your feeds importer. The column must contain only the system menu name. As it is, there are no options to select the parent item. However, I've been reading the feeds issue queue: there is an effort to make feeds more language aware when translating fields. The above patch wouldn't work in that situation. I'm waiting to see how things progress before updating the patch.
Cheers

pindaman’s picture

so my csv should look like:

"menu-name";"menu-item";"child-item";
"menumain-menu";"apples";"green";

??
sorry for the questions.
I have been playing around with feeds now for over a week..
I am getting a bit crazy now.

nlambert’s picture

The mapped field (only one field) should only contain the system menu name. The name/title of the menu item will be created automatically based on the node title. The node title field should therefore be mapped before the "Menu Name" field.

We had many nodes to import and many needed a menu item in various different menus. The patch was pratical for that, but does not allow for menu hierarchy.

Another consideration when using the patch is that the menu item title cannot differ from the node's title.

The last consideration, I believe, is language. When translating the full node this isn't a problem, but when translating using field translation I don't believe this is possible (but I could be mistaken).

Hope this helps.

pindaman’s picture

Thanks for clearing all out to me
as menu items need to be different than the node titles this is not useable for my current project.

But I can image it being usefull in other projects.
Thanks for you quick replies.

regards,
Pinda

sutharsan’s picture

Status: Active » Needs work

The added functionality is minimal, but is a good starting point. Only a few code style fixes to do.

+        break;        
+    
+    // If menu is enabled expose menu name.
+      );
+    }    

Trailing white space in various places.

sutharsan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB

Rerolled the patch for latest dev release. Added (empty) menu description property.

nlambert’s picture

Definately basic functionality indeed. In order to add more functionality there should be a different mapper for each menu composant (menu name mapper, menu title mapper, menu parent mapper, etc...).

@Sutharsan: What do you think?

sutharsan’s picture

Yes, very basic (I code my way around the basics). Agree, there should be facilities to import all the other properties of a menu item too.

  • Menu title: defaults to node title.
  • path: node/{nid}
  • Description: default empty. Nice but no priority.
  • Enabled: default enabled. Nice but no priority.
  • Show as expended: default disabled. Nice but no priority.
  • Parent link: default to selectable menu-item or reference to other imported field
  • Weight: default 0 or automatically increase.

Re . "Parent link" One field in the imported data set was a unique identified "ID". My "Parent" import field contained the value of an "ID" field. The "ID" value precedes the "Parent" value in the import data, e.g. ID = 'foo5' is in row 5, Parent = 'foo5' is used in row 6, 7 or further.

skriptble’s picture

This is working great for me. I was just wondering when there would be a commit for it, at least in the dev branch?

crutch’s picture

This is not working well for me with Alpha-8 and the patch above importing an XML feed using Xpath for mapping. So since I only really need them in the menu system for accurate breadcrumbs, I use https://drupal.org/project/crumbs

attisan’s picture

just in case someone needs a more sophisticated version, I have set up a sandbox with more options.
https://drupal.org/sandbox/attisan/2144379

feel free to comment and request.

greets

crutch’s picture

I would like use menu in feeds but at this time ended up using Views & Views Accordion to create a Menu Block for left margin for specific sets of content. It works for this case because only showing 2 levels deep in primary menu. Views Accordion may not be required but didn't try without.

Create new View Block, add Content: Type in filter criteria, add Content: Type and Content: Title in fields.

Format: Views Accordion

Settings
Group: Content: Type
Use rendered output to group rows = true
Allow all rows to be closed = true
Use group header as accordion header = true
Animation: Slide
Event: Click
Autoheight = false
Clearstyle = true

Sort Criteria
Will have to locate a field that will sort it like you want

Content Type Names
Had to alter the content type names to get the parent menu item names correct

Style to taste

twistor’s picture

Component: Feeds Import » Code
Issue summary: View changes
Status: Needs review » Closed (won't fix)

Sorry to be a buzzkill.

This seems simple at first. But, it's going to spiral into mapping to menu by GUIG, URL. Mapping the menu parent, and who knows what else.

This is all possible from a contrib module.

hjvfy’s picture

it's not working
First I used last release of feeds, then I specially dowloaded and try to use 7.x-2.0-alpha8+71-dev version, but no result.

in mapping page I see :
item "Menu name (menu_name) The system name of the menu in which to add a link. The menu must be enabled in the content type".

but after importing against my menu title is the same name of menu, which is in title of node

medwassim’s picture

we need feeds module to import nodes. in nodes content type we define the menu parent.
in my case the simple way is hook_node_insert or hook_node_presave like this :

/**
* Implements hook_node_insert().
*/
function MY_MODULE_node_insert($node){

if($node->type == 'MY_CONTENT_TYPE'){
$menu = variable_get('menu_parent_' . $node->type, 'main-menu:0');
$menu = explode(':', $menu);
if($menu[0] == 'main-menu' && $menu[1] != 0) { //main menu && not in first level
$node->menu['link_title'] = $node->title;
$node->menu['link_path'] = 'node/' . $node->nid;
$node->menu['menu_name'] = 'main-menu';
$node->menu['module'] = 'menu';
$node->menu['plid'] = $menu[1];
$node->menu['customized'] = 1;
$node->menu['enabled'] = 1;
//$node->menu['hidden'] = 1; //disable the menu link

$node->path['pathauto'] = 1;
}
}
}

nodes are attached to menu and alias is generated correctly.

portulaca’s picture

+1

xaqrox’s picture

+1 for attisan's sandbox project, worked really well for me. https://www.drupal.org/sandbox/attisan/2144379

pierre-nono’s picture

Attisan's sandbox is exactly what I needed for a important project !
Thanks you very much !

I still got these two errors, but there are just warning and notice :

Warning: Illegal offset type in isset or empty in menu_cache_clear() (line 2690 of C:\xampp\htdocs\Feeds\includes\menu.inc).

Notice: Array to string conversion in menu_cache_clear() (line 2691 of C:\xampp\htdocs\Feeds\includes\menu.inc).

And I can't seem to make it work for the main menu, but it's probably my fault.

And , just for info another close solution is this sandbox project:
https://www.drupal.org/sandbox/darth-romios/2639162