You are here

function pardot_menu_links_discovered_alter in Pardot Integration 2.x

Implements hook_menu_links_discovered_alter().

File

./pardot.module, line 53
Contains pardot.module.

Code

function pardot_menu_links_discovered_alter(&$links) {
  $route_provider = \Drupal::service('router.route_provider');
  $bundles = \Drupal::entityTypeManager()
    ->getStorage('contact_form')
    ->loadMultiple();
  $base_plugin_definition = [
    'id' => 'admin_toolbar_tools.extra_links',
  ];
  foreach ($bundles as $machine_name => $bundle) {
    $content_entity_bundle_root = 'entity.contact_form.edit_form.' . $machine_name;

    // Normally, the edit form for the bundle would be its root link.
    $content_entity_bundle = 'contact_form';
    $i = $route_provider
      ->getRoutesByNames([
      'entity.' . $content_entity_bundle . '.pardot_form_mapping',
    ]);
    if (count($route_provider
      ->getRoutesByNames([
      'entity.' . $content_entity_bundle . '.pardot_form_mapping',
    ])) === 1) {
      $links['entity.' . $content_entity_bundle . '.pardot_form_mapping.' . $machine_name] = [
        'title' => t('Pardot Form Mapping'),
        'route_name' => 'entity.' . $content_entity_bundle . '.pardot_form_mapping',
        'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
        'route_parameters' => [
          $content_entity_bundle => $machine_name,
        ],
        'weight' => 4,
      ] + $base_plugin_definition;
    }
  }
}