You are here

protected function MenuDevelGenerate::generateMenus in Devel 8.2

Same name and namespace in other branches
  1. 8.3 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateMenus()
  2. 8 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateMenus()
  3. 4.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateMenus()

Generates new menus.

Parameters

int $num_menus: Number of menus to create.

int $title_length: (optional) Maximum length per menu name.

Return value

array Array containing the generated vocabularies id.

1 call to MenuDevelGenerate::generateMenus()
MenuDevelGenerate::generateElements in devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php
Business logic relating with each DevelGenerate plugin

File

devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php, line 300

Class

MenuDevelGenerate
Provides a MenuDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

protected function generateMenus($num_menus, $title_length = 12) {
  $menus = array();
  for ($i = 1; $i <= $num_menus; $i++) {
    $name = $this
      ->getRandom()
      ->word(mt_rand(2, max(2, $title_length)));
    $menu = $this->menuStorage
      ->create(array(
      'label' => $name,
      'id' => 'devel-' . mb_strtolower($name),
      'description' => $this
        ->t('Description of @name', array(
        '@name' => $name,
      )),
    ));
    $menu
      ->save();
    $menus[$menu
      ->id()] = $menu
      ->label();
  }
  return $menus;
}