You are here

public function SimpleMegaMenuTest::createMenuLink in Simple Mega Menu 2.0.x

Same name and namespace in other branches
  1. 8 src/Tests/SimpleMegaMenuTest.php \Drupal\simple_megamenu\Tests\SimpleMegaMenuTest::createMenuLink()

Creates a menu link given text and path.

Parameters

string $text: The menu link text.

string $path: The menu link path. Available path : 'route:<front>' or 'internal:/people' or 'entity:node/' . $node->id().

int $weight: The menu link weight.

string $menu: The menu to add the link to.

int $expanded: The menu link is expanded or not if it has children.

string $parent: The parent menu item uuid to attach the link to.

string $langcode: The langcode.

Return value

\Drupal\menu_link_content\Entity\MenuLinkContent The saved menu link.

1 call to SimpleMegaMenuTest::createMenuLink()
SimpleMegaMenuTest::testMegaMenu in src/Tests/SimpleMegaMenuTest.php
Tests that the home page loads with a 200 response.

File

src/Tests/SimpleMegaMenuTest.php, line 119

Class

SimpleMegaMenuTest
Simple test to ensure that main page loads with module enabled.

Namespace

Drupal\simple_megamenu\Tests

Code

public function createMenuLink($text, $path, $weight = 0, $menu = 'main', $expanded = 1, $parent = NULL, $langcode = 'en') {

  /* @var  \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link */
  $menu_link = MenuLinkContent::create([
    'title' => $text,
    'link' => [
      'uri' => $path,
    ],
    'menu_name' => $menu,
    'weight' => $weight,
    'expanded' => $expanded,
    'langcode' => $langcode,
  ]);
  if ($parent !== NULL) {
    $menu_link
      ->set('parent', 'menu_link_content:' . $parent);
  }
  $menu_link
    ->save();
  return $menu_link;
}