1

Pathauto is great, in that it allows you to set the URL alias of a node to some pattern like '[node:menu-link:parent:url:path]/[node:title]-DEV' for DEV content type.

I am trying to build a single menu containing menu links for two content types. There is typically a node titled: nodecontent for each content type, then with pathauto we set the URL for the DEV content to be nodecontent-DEV by using the above pattern. It allows us to append a string, which is great.

I cannot figure out how to do this dynamically for menu links though. Since the only automatic action Drupal does is fill in the title for 'Menu link title'.

It would be great if I could append -DEV to each menu link (for that content type), so in one menu I could have: Country>State>City and Country>State>City-DEV.

1 Answer 1

0

You could use the Automatic Node Titles module to create the titles including the DEV string, which depending on your other settings could appear in the menu:

"auto_nodetitle" is a small and efficient module that allows hiding of the content title field in the form. To prevent empty content title fields one can configure it to generate the title by a given pattern.

When the token module is installed it's possible to use various node data for the auto generated title - e.g. use the text of a CCK field (since 5.x).

EDIT

You could also create a simple module to change the title of the nodes for the DEV content type:

Custom Node Title

custom_node_title.info

name = Custom Title (DEV)
core = 7.x
description = Appends appropriate titles with DEV
package = custom

custom_node_title.module

<?php
/**
*   Custom Node Title Module
**/

function custom_node_title_node_presave($node)
{
    /* only run if node type is correct and '-DEV' is not found in title to prevent duplication */
    if($node->type == 'article' && strpos($node->title, '-DEV') === false)
    {
        $node->title .= '-DEV'; /* add '-DEV' to title */
        $node->menu['link_title'] = $node->title; /* reset menu link to new title */
    }
}

In this example, it changes the title of an Article content type to include -DEV at the end.

5
  • Hmm, this is neat, but it won't let me allow users to set a title, AND have the module append a -DEV. It's either or; 'Disabled' or 'Automatically generate the title and hide the title field' are the two settings. If I enable the second setting, and use a token for [node:title]-DEV, there is no way to allow users to set the title. Jun 6, 2015 at 16:38
  • haha, I actually figured out the new text field method with auto_nodetitle, thanks for the mini-module. the original issue still exists though. automatically setting the 'menu link title' is what I am after. I tried using auto_menutitle to do this, but since the real title field is blank on node creation, the menu link title does not get set. Jun 9, 2015 at 16:53
  • Problem with that module is, each time a node is saved, it gets another -DEV. Save a node once, node-DEV, twice, node-DEV-DEV etc. This aside, the menu link title is still not being populated/updated with the -DEV or -DEV-DEV. Jun 10, 2015 at 13:11
  • Perhaps this is the reason, from this issue "Although this field is usually auto-filled via JavaScript based on the node title, there are situations where that won't happen (for example, if the node title field is being hidden on the form and generated automatically)." I realize this is referencing D8, but it seems accurate. Jun 10, 2015 at 13:17
  • custom module does the trick, thank you so much for the effort! Jun 10, 2015 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.