You are here

function devel_generate_menu_links_discovered_alter in Devel 4.x

Same name and namespace in other branches
  1. 8.3 devel_generate/devel_generate.module \devel_generate_menu_links_discovered_alter()
  2. 8 devel_generate/devel_generate.module \devel_generate_menu_links_discovered_alter()
  3. 8.2 devel_generate/devel_generate.module \devel_generate_menu_links_discovered_alter()

Implements hook_menu_links_discovered_alter().

File

devel_generate/devel_generate.module, line 18

Code

function devel_generate_menu_links_discovered_alter(&$links) {
  $devel_generate_plugins = \Drupal::service('plugin.manager.develgenerate')
    ->getDefinitions();
  foreach ($devel_generate_plugins as $id => $plugin) {
    $label = $plugin['label'];
    $links["devel_generate.{$id}"] = [
      'title' => new TranslatableMarkup("Generate @label", [
        '@label' => $label,
      ]),
      'parent' => 'devel_generate.admin_config_generate',
      'description' => $plugin['description'],
      'route_name' => "devel_generate.{$id}",
      'provider' => 'devel_generate',
    ];
  }

  // Store the basic link info for repeated use. Each of the three actual links
  // require subtle variations on this.
  $basics = [
    'title' => new TranslatableMarkup('Generate'),
    'description' => new TranslatableMarkup('Generate realistic items (content, users, menus, etc) to assist your site development and testing.'),
    'route_name' => 'devel_generate.admin_config_generate',
    'provider' => 'devel_generate',
  ];

  // Define a separate group on admin/config page, so that 'Generate' has its
  // own block with all the generate links.
  $links['devel_generate.admin_config_generate'] = [
    'parent' => 'system.admin_config',
    // The main development group has weight -10 in system.links.menu.yml so use
    // -9 here as this block should be near but just after it on the page.
    'weight' => -9,
  ] + $basics;

  // Add a link in the main development group, to allow direct access to the
  // the Generate page and to make the back breadcrumb more useful.
  $links['devel_generate.generate'] = [
    'title' => new TranslatableMarkup('Devel generate'),
    'parent' => 'system.admin_config_development',
  ] + $basics;

  // Define a top-level link (with no parent) in the 'devel' menu. This also
  // means that it will be available in the devel admin toolbar.
  $links['devel_generate.generate2'] = [
    'menu_name' => 'devel',
  ] + $basics;
}