You are here

public static function MenuCreator::createMenu in GatherContent 8.4

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

Create a menu link to the imported node.

1 call to MenuCreator::createMenu()
Importer::import in src/Import/Importer.php
Import a single GatherContent item to Drupal.

File

src/Import/MenuCreator.php, line 16

Class

MenuCreator
Class for creating menus after import.

Namespace

Drupal\gathercontent\Import

Code

public static function createMenu(NodeInterface $entity, $parentMenuItem) {
  $isContentTypeTranslatable = Importer::isContentTypeTranslatable($entity
    ->bundle());
  $isMenuTranslatable = static::isMenuTranslatable();
  $menuLinkDefaults = menu_ui_get_menu_link_defaults($entity);
  if (!(bool) $menuLinkDefaults['id']) {
    if ($isContentTypeTranslatable && $isMenuTranslatable) {
      $languages = $entity
        ->getTranslationLanguages();
      $originalLinkId = NULL;
      foreach ($languages as $langcode => $language) {
        $localized_entity = $entity
          ->hasTranslation($langcode) ? $entity
          ->getTranslation($langcode) : NULL;
        if (!is_null($localized_entity)) {
          static::createMenuLink($entity
            ->id(), $localized_entity
            ->getTitle(), $parentMenuItem, $langcode, $originalLinkId);
        }
      }
    }
    else {
      static::createMenuLink($entity
        ->id(), $entity
        ->getTitle(), $parentMenuItem);
    }
  }
}