hi all

this is my first post ever on this site (yeeeaay! ;) ), so please forgive me if I should have not created a new issue or if I do something else incredibly stupid or newbie-ish, but for the last couple of hours I have been pulling my hair out because of this one: on some links in my menu, the tokens are neatly replaced, as for others, nothing (not even the token gets removed if I check the box, so they just are not being treated...).

I traced down the problem to the menu_token_menu_links_discovered_alter(&$links) method (where the replace magic happens), and noticed that not every menu item on my site has been included in the $links parameter (some mumbo jumbo links like node_addform, and every internal (nod/somenumber) link are there, but none of my external (https://somesite/somepage) menu links seem to have made it to the links collection...

Am I doing something something wrong here, or am I overseeing something terribly obvious?

I tried to dive into the core code, but I don't seem to be able to locate the exact spot as to where the filtering of these menu items happens ("discovery" I think it is called if i'm not mistaken...)...

Or does the menu token module not treat these so called "external" (of type http://blabla) links?

the few strands of hair left standing on top of my head, are eternally grateful for any clarification/aid on the matter ;)

kind regards
Christophe

CommentFileSizeAuthor
#4 undiscoveredLinks.patch2.22 KBpeter.draucbaher

Comments

menwithbeards created an issue. See original summary.

peter.draucbaher’s picture

Thanks a lot for this. It is bug.

$relevant_links = array_filter($links, function ($k) {
if (!isset($k['id'])) {
$k['id'] = 0;
}
return strpos($k['id'], 'menu_link_content:') === 0;
});

I am stripping menu items away. Have to repair it. It is too strict.
Have to investigate how external menus are handled in menu alter they are probably not menu_link_content...

peter.draucbaher’s picture

Somehow the system stores links inside menu_link_content_data as rediscover 0 and they do not get loaded in definitions.

/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// Get all custom menu links which should be rediscovered.
$entity_ids = $this->entityManager->getStorage('menu_link_content')->getQuery()
->condition('rediscover', TRUE)
->execute();
$plugin_definitions = [];
$menu_link_content_entities = $this->entityManager->getStorage('menu_link_content')->loadMultiple($entity_ids);
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link_content */
foreach ($menu_link_content_entities as $menu_link_content) {
$plugin_definitions[$menu_link_content->uuid()] = $menu_link_content->getPluginDefinition();
}
return $plugin_definitions;
}

have to fix it.

peter.draucbaher’s picture

StatusFileSize
new2.22 KB

Cheating a patch and will commit.

  • peter.draucbaher authored f2a8e67 on 8.x-1.x
    Issue #2909280 by menwithbeards, peter.draucbaher: Can external menu...
peter.draucbaher’s picture

Status: Active » Needs review
menwithbeards’s picture

Hi Peter

patch in #4 works like a charm! I cannot thank you enough for this fix! Thank you thank you thank you!

keep up the amazing work and again, a very big thank you! (always a great feeling whilst pulling an all-nighter, to be able to take an issue off of the things-to-do-before-going-live-in-24-hours list ;)

peter.draucbaher’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

letrollpoilu’s picture

I'm using the alpha3 version with Drupal 8.0.1 and this is still not working :(

I tried to apply the patch but this is not working:

error: while searching for:

}

/**
 * Replace links with tokens.
 */
function menu_token_menu_links_discovered_alter(&$links) {

  // Load configuration from entity.
  $relevant_links = array_filter($links, function ($k) {
    if (!isset($k['id'])) {

error: patch failed: menu_token.module:410
error: menu_token.module: patch does not apply
Checking patch src/Service/MenuTokenContextManager.php...
error: while searching for:
  }

  /**
   * @param $relevantLink
   * @param $config
   */
  public function prepareContextualLinks($relevantLink, $config) {


error: patch failed: src/Service/MenuTokenContextManager.php:39
error: src/Service/MenuTokenContextManager.php: patch does not apply