You are here

public function MenuDevelGenerate::generateElements in Devel 4.x

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 devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::generateElements()
  3. 8.2 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 198

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 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']) {
    list($menus_deleted, $links_deleted) = $this
      ->deleteMenus();
    $this
      ->setMessage($this
      ->t('Deleted @menus_deleted menu(s) and @links_deleted other link(s).', [
      '@menus_deleted' => $menus_deleted,
      '@links_deleted' => $links_deleted,
    ]));
  }

  // Generate new menus.
  $new_menus = $this
    ->generateMenus($values['num_menus'], $values['title_length']);
  if (!empty($new_menus)) {
    $this
      ->setMessage($this
      ->formatPlural(count($new_menus), 'Created the following 1 new menu: @menus', 'Created the following @count new menus: @menus', [
      '@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
    ->formatPlural(count($new_links), 'Created 1 new menu link.', 'Created @count new menu links.'));
}