You are here

trait MenuLinkContentTrait in Menu Admin per Menu 8

Provides methods to create menu_content_links from given values.

This trait is meant to be used only by test classes.

Hierarchy

1 file declares its use of MenuLinkContentTrait
MenuAdminPerMenuMenuPagesTest.php in tests/src/Functional/MenuAdminPerMenuMenuPagesTest.php

File

tests/src/Traits/MenuLinkContentTrait.php, line 14

Namespace

Drupal\Tests\menu_admin_per_menu\Traits
View source
trait MenuLinkContentTrait {
  use RandomGeneratorTrait;

  /**
   * Creates a menu link content based on default settings.
   *
   * @param array $values
   *   An array of settings to change from the defaults.
   *   Example: 'menu_name' => 'foo'.
   *
   * @return \Drupal\menu_link_content\MenuLinkContentInterface
   *   The created menu link.
   */
  protected function createMenuContentLink(array $values = []) : MenuLinkContentInterface {
    $menu_link = MenuLinkContent::create($values + [
      'title' => $this
        ->randomMachineName(),
      'menu_name' => 'main',
      'link' => [
        'uri' => 'route:<front>',
      ],
      'provider' => 'menu_link_content',
    ]);
    $menu_link
      ->save();
    return $menu_link;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MenuLinkContentTrait::createMenuContentLink protected function Creates a menu link content based on default settings.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.