You are here

protected static function MenuCreator::getMenuByGcId in GatherContent 8.4

Same name and namespace in other branches
  1. 8.5 src/Import/MenuCreator.php \Drupal\gathercontent\Import\MenuCreator::getMenuByGcId()

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 MenuCreator::getMenuByGcId()
MenuCreator::createMenuLink in src/Import/MenuCreator.php
Create menu link if requested.

File

src/Import/MenuCreator.php, line 123

Class

MenuCreator
Class for creating menus after import.

Namespace

Drupal\gathercontent\Import

Code

protected static function getMenuByGcId(&$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();
    }
  }
}