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
- trait \Drupal\Tests\menu_admin_per_menu\Traits\MenuLinkContentTrait uses RandomGeneratorTrait
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\TraitsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuLinkContentTrait:: |
protected | function | Creates a menu link content based on default settings. | |
RandomGeneratorTrait:: |
protected | property | The random generator. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | 1 |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. |