You are here

function _gc_get_menu_by_gc_id in GatherContent 8.3

Same name and namespace in other branches
  1. 8 gathercontent.module \_gc_get_menu_by_gc_id()

Load menu name and menu link id for other languages by node ID.

Parameters

int $mlid: Menu link ID.

string $menu_name: Name of the menu.

string|null $language: Langcode if menu link item will be translatable.

1 call to _gc_get_menu_by_gc_id()
gc_create_menu_link in ./gathercontent.module
Create menu link if requested.

File

./gathercontent.module, line 462
Main module file for GatherContent module.

Code

function _gc_get_menu_by_gc_id(&$mlid, &$menu_name, $language = NULL) {

  // Load node by gc_id.
  $node_ids = \Drupal::entityQuery('node')
    ->condition('gc_id', $mlid)
    ->execute();
  if (!empty($node_ids)) {

    // Load menu_link by node_id.
    $node = reset($node_ids);
    $ml_result = \Drupal::entityQuery('menu_link_content')
      ->condition('link.uri', 'entity:node/' . $node);
    if (!is_null($language)) {
      $ml_result
        ->condition('langcode', $language);
    }
    $mls = $ml_result
      ->execute();
    if (!empty($mls)) {
      $ml = reset($mls);
      $ml_object = MenuLinkContent::load($ml);
      $menu_name = $ml_object
        ->getMenuName();
      $mlid = 'menu_link_content:' . $ml_object
        ->uuid();
    }
  }
}