1

Let say I have a menu item with these attributes

'title' => 'Menu Title',
'link' => ['uri' => 'internal:/taxonomy/term/1217'],
'menu_name' => 'my-menu',
'expanded' => TRUE,

I can find all the menus by their title, e.g.,

 $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
                ->loadByProperties(['title' => 'Menu Title']);

if ($menu_link = reset($menu_links)) {
// Get the pid of the first menu
    $menu_pid = $menu_link->getPluginId();
}

Then I tried to retrieve menu by the link property, and I couldn't. I tried:

 $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
                ->loadByProperties(['link' => array('uri' => 'internal:/taxonomy/term/1217')]);

 $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
                ->loadByProperties(['link' => ['uri' => 'internal:/taxonomy/term/1217']]);

 $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
                ->loadByProperties(['uri' => 'internal:/taxonomy/term/1217']);

None of them worked.

2

Try the property link.uri:

$menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')
  ->loadByProperties(['link.uri' => 'internal:' . $path]);

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.