You are here

public function SimpleMegaMenuTest::createMegaMenu in Simple Mega Menu 8

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

Create a MegaMenu entity.

Parameters

string $type: The type.

string $title: The title.

string $langcode: The langcode.

string $uid: The author uid.

array $fields: Fields to set.

bool $status: The publishing status.

Return value

\Drupal\simple_megamenu\Entity\SimpleMegaMenuInterface The mega menu created.

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

File

src/Tests/SimpleMegaMenuTest.php, line 155

Class

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

Namespace

Drupal\simple_megamenu\Tests

Code

public function createMegaMenu($type, $title, $langcode, $uid = '1', array $fields = [], $status = TRUE) {

  /* @var  \Drupal\simple_megamenu\Entity\SimpleMegaMenu $mega_menu */
  $mega_menu = SimpleMegaMenu::create([
    'type' => $type,
    'name' => $title,
    'uid' => $uid,
    'status' => $status,
    'langcode' => $langcode,
  ]);
  if (empty($fields)) {
    $mega_menu
      ->save();
  }
  else {
    foreach ($fields as $field_name => $value) {
      if ($mega_menu
        ->hasField($field_name)) {
        $mega_menu
          ->set($field_name, $value);
      }
    }
    $mega_menu
      ->save();
  }
  return $mega_menu;
}