You are here

public function MenuDevelGenerate::generateElements in Devel 8

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

Business logic relating with each DevelGenerate plugin

Parameters

array $values: The input values from the settings form.

Overrides DevelGenerateBase::generateElements

File

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

Class

MenuDevelGenerate
Provides a MenuDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function generateElements(array $values) {

  // If the create new menus checkbox is off, set the number of new menus to 0.
  if (!isset($values['existing_menus']['__new-menu__']) || !$values['existing_menus']['__new-menu__']) {
    $values['num_menus'] = 0;
  }
  else {

    // Unset the aux menu to avoid attach menu new items.
    unset($values['existing_menus']['__new-menu__']);
  }

  // Delete custom menus.
  if ($values['kill']) {
    $this
      ->deleteMenus();
    $this
      ->setMessage($this
      ->t('Deleted existing menus and links.'));
  }

  // Generate new menus.
  $new_menus = $this
    ->generateMenus($values['num_menus'], $values['title_length']);
  if (!empty($new_menus)) {
    $this
      ->setMessage($this
      ->t('Created the following new menus: @menus', array(
      '@menus' => implode(', ', $new_menus),
    )));
  }

  // Generate new menu links.
  $menus = $new_menus;
  if (isset($values['existing_menus'])) {
    $menus = $menus + $values['existing_menus'];
  }
  $new_links = $this
    ->generateLinks($values['num_links'], $menus, $values['title_length'], $values['link_types'], $values['max_depth'], $values['max_width']);
  $this
    ->setMessage($this
    ->t('Created @count new menu links.', array(
    '@count' => count($new_links),
  )));
}