I was asked to tweak a pathauto pattern for a node that is in a specific menu. I couldn’t find documentation on this so here’s my approach to this:
Use pathauto_pattern_alter hook in a custom module.
If the node type is “standard” is being created, updated, or on bulkupdate, then set the pattern to something specific.
this was the easy bit. Finding the node’s menu was more difficult. I looked through the context data and got $context[‘data’][‘node’]->menu[‘menu_parent’]. Then I checked if the $context[‘data’][‘node’]->menu[‘menu_parent’] id starts with the machine name of the menu ‘my_menu’ using hard-coded substr().
function my_module_pathauto_pattern_alter(&$pattern, array $context)
{
if ($context['module'] == 'node' && $context['bundle'] == 'standard' && ($context['op'] == 'insert' or $context['op'] == 'update' or $context['op'] == 'bulkupdate')) {
if (substr($context['data']['node']->menu['menu_parent'], 0, 8) === 'my_menu:') {
$pattern->setPattern('hello/[node:menu-link:parents:join:/]/[node:title]');
}
}
}