Not sure if this is technically a bug or considered out of scope for the module, but tokens are not being parsed and substituted in a query string if one is added to the menu URL.

e.g. /node/add/page/parent/[current-page:url:arg:1]
becomes: /node/add/page/parent/69

but: /node/add/page?edit[field_parent]=[current-page:url:arg:1]
becomes: /node/add/page?edit%5Bfield_parent%5D=%5Bcurrent-page%3Aurl%3Aarg%3A1%5D

Issue fork menu_token-2948260

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

scott.whittaker created an issue. See original summary.

doxigo’s picture

I have the same problem, it only works if there's anything before the token in URL

xangy’s picture

Assigned: Unassigned » xangy
xangy’s picture

StatusFileSize
new3.67 KB
new2.05 KB

Please review this. Adding the patch for Drupal core as well. See: https://www.drupal.org/project/drupal/issues/2978657#comment-12647144

xangy’s picture

Assigned: xangy » Unassigned
Status: Active » Needs review
doxigo’s picture

I ended up with the following errors:

Error: Uncaught TypeError: Argument 1 passed to Drupal\Core\Utility\Token::replaceArray() must be of the type
array, null given, called in /Users/sohail/Sites/setboxy/modules/contrib/menu_token/menu_token.module on line
393 and defined in /Users/sohail/Sites/setboxy/core/lib/Drupal/Core/Utility/Token.php:278
Stack trace:
#0 /Users/sohail/Sites/setboxy/modules/contrib/menu_token/menu_token.module(393):
Drupal\Core\Utility\Token->replaceArray(NULL, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#1 /Users/sohail/Sites/setboxy/modules/contrib/menu_token/menu_token.module(452):
replace_links_with_tokens(Object(Drupal\token\Token), 'query', Array, Array,
Object(Drupal\Core\Render\BubbleableMetadata))
#2 /Users/sohail/Sites/setboxy/core/lib/Drupal/Core/Extension/ModuleHandler.php(539):
menu_token_menu_links_discovered_alter(Array, NULL, NULL)
#3 /Users/sohail/Sites/setboxy/core/lib/Drupal/Core/Menu/MenuLinkManager.php(167):
Drupal\Core\Extension\ModuleHandler->alter('menu_links_disc...', Array)
#4 /Users/soha in /Users/sohail/Sites/setboxy/core/lib/Drupal/Core/Utility/Token.php, line 278

xangy’s picture

Assigned: Unassigned » xangy
Status: Needs review » Active
hypertext200’s picture

hypertext200’s picture

Status: Active » Needs review
StatusFileSize
new4.72 KB

Patch attached, but this approach is completely different and does not require a core patch.

hypertext200’s picture

Status: Needs review » Needs work

This patch doesn't work when you have node in your menu link.

karimbou’s picture

Notice: Array to string conversion in Drupal\Core\Theme\ThemeInitialization->getActiveTheme() (line 179 of core/lib/Drupal/Core/Theme/ThemeInitialization.php).

Undefined index: add_query_parameters in menu_token_prepare_context_replacement() (line 427 of modules/contrib/menu_token/menu_token.module).
menu_token_prepare_context_replacement(Array)

hypertext200’s picture

Status: Needs work » Needs review
StatusFileSize
new5.13 KB
lamp5’s picture

Status: Needs review » Needs work

@heshanlk you attached a diff but where is a patch??

steveoriol’s picture

The patch (which is called diff), works very well for me ;-)
Thank you
I installed it on dev version

vuil’s picture

Status: Needs work » Active
StatusFileSize
new5.13 KB

Update #12 to be a patch.

vuil’s picture

Assigned: xangy » Unassigned
Status: Active » Needs review
vuil’s picture

Status: Needs review » Reviewed & tested by the community
develcuy’s picture

Category: Bug report » Feature request
Status: Reviewed & tested by the community » Needs work

Thank you all for your contributions and feedback. Just wanted to note that this issue is more a feature request than a bug report, since we are adding new functionality and interface changes. Also, I'm not sure if Menu Token should handle query strings, since the cache can do all sort of things to freeze some tokens that are sensitive to context. That said, I think that this functionality is more appropriate in Javascript OR that we should handle a few cached use cases. In all cases, we should inform the user about how cache can alter her expectations.

shree.yesare’s picture

Notice: Undefined index: add_query_parameters in Drupal\menu_token\Service\MenuTokenContextManager->prepareContextualLinks() (line 67 of /var/www/centara/docroot/modules/contrib/menu_token/src/Service/MenuTokenContextManager.php)

shree.yesare’s picture

StatusFileSize
new4.97 KB

Update #15 to be a patch.

shree.yesare’s picture

StatusFileSize
new5.18 KB

Re-rolling from patch in #15

vuil’s picture

Status: Needs work » Needs review
timotej-pl’s picture

StatusFileSize
new5.32 KB

Patch from #21 could not be applied on current dev branch, neither it could not be at the time of posting it.
Added a patch that fixed that problem and also issue from #19.
Needs review.

develcuy’s picture

Version: 8.x-1.x-dev » 9.1.x-dev
Status: Needs review » Needs work

Please re-roll for 9.1.x

mahmoud barhouma’s picture

StatusFileSize
new13.13 KB

muriqui made their first commit to this issue’s fork.

muriqui’s picture

Status: Needs work » Needs review

Opened merge request:

  • Re-rolls the patch for 9.1.x.
  • Fixes a PHP warning that could occur when parsing the query string.
  • Fixes the query string tokens not being added to the link when using Context to resolve the tokens.