This bug appears if you have field_collection installed and if you have some fields with this type.

If I open the page referenced by the menu: "Structure > menus > Administration" /admin/structure/menu/manage/admin I got the following error:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.field_collection.delete_form" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 187 of core/lib/Drupal/Core/Routing/RouteProvider.php).

Drupal\Core\Routing\UrlGenerator->getRoute('entity.field_collection.delete_form') (Line: 277)
Drupal\Core\Routing\UrlGenerator->generateFromRoute('entity.field_collection.delete_form', Array, Array, 1) (Line: 105)
Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('entity.field_collection.delete_form', Array, Array, 1) (Line: 735)
Drupal\Core\Url->toString(1) (Line: 162)
Drupal\Core\Utility\LinkGenerator->generate('Supprimer', Object) (Line: 94)
Drupal\Core\Render\Element\Link::preRenderLink(Array)
call_user_func(Array, Array) (Line: 381)

If I am not wrong, the menu items are generated by the function

function admin_toolbar_tools_menu_links_discovered_alter(&$links)

located in the admin_toolbar_tools.module file.

In this function, I can see the following:

function admin_toolbar_tools_menu_links_discovered_alter(&$links) {
.
.
.
  // Adds common links to entities.
  foreach ($content_entities as $module_name => $entities) {
    $config_entity = $entities['config_entity'];
    $content_entity = $entities['content_entity'];
    foreach ($entityTypeManager->getStorage($config_entity)->loadMultiple() as $machine_name => $bundle) {
.
.
.
      $links["entity." . $config_entity . ".delete_form." . $machine_name] = array(
        'title' => t('Delete'),
// HERE IS THE PROBLEM
        'route_name' => "entity." . $config_entity . ".delete_form",
//
        'menu_name' => 'admin',
        'parent' => "entity." . $config_entity . ".edit_form." . $machine_name,
        'route_parameters' => array($config_entity => $machine_name),
        'weight' => 5,
      );
    }
  }
.
.
.
}

The problem is the following: with field_collection, the delete form route is not called "entity.field_collection.delete_form" but "entity.field_collection_item.delete_form" (see my comment in the code)
I don't know if this is a FC problem or an ADMIN_TOOL problem

There is another problem with this chunk of code: the parent of those links is wrongly attributed. The result is a lot of links added at the root of the admin menu (invisible in the UI), the parent should be "Structure > Field Collections"

Comments

DuneBL created an issue. See original summary.

dunebl’s picture

Here is a small temporary ugly patch but it is doing the job.
-The delete form route is corrected for field_collection
-The parent key is also corrected and all the menu links for the field_collection are now available.

romainj’s picture

We are currently facing similar problems with other modules such as the Group module. The problem is that we build the links based on the entity type machine names. But it does not work the same way for all of the content entity types. I will try to find a generic fix but for the moment it's easier to remove those entity types from the list so that we do not add not working routes. Thanks.

  • romainj committed 88477c9 on 8.x-1.x
    Issue #2779251 by DuneBL, romainj: Wrong integration of field_collection...

  • romainj committed ccc7d61 on 8.x-1.x
    Issue #2779251 by romainj, DuneBL: Wrong integration of field_collection...
romainj’s picture

I changed code so that we do not have the error related to the non existing route. I will check for the second problem.

  • romainj committed 195f503 on 8.x-1.x
    Issue #2779251 by romainj, DuneBL: Wrong integration of field_collection...
romainj’s picture

Code committed so that we should not have any menu link related to non existing routes.

eme’s picture

:)

dunebl’s picture

ok, thanks for this.
But we loose all the field_collection 2nd level links that were alive after my patch.
Don't you think it is a good thing to have them?
Also, please take a look at another patch I have made: https://www.drupal.org/node/2731369
This patch is adding many other links for free...

romainj’s picture

I am sorry that some Field Collection links are now missing. We can only rely on routes provided by Drupal core as those related to Entity API and the Field UI module. The Field Collection routes do not follow those standards so we need to be specific to that module. It can be a bit tricky because if there is any change in Field Collection route definitions we would have to adapt our code. A better approach could be to ask the maintainers to follow closely Drupal standards as far as entity type route definitions are concerned.

dunebl’s picture

Ok, I understand your concern... Even if I am not fully agree with it; but I can live with that.
Do you have a list of standardized route that I can transmit to the field_collection maintainers (and any other module's maintainer that you feel it is a good idea)

Do you had some time to take a look at my auto-discover tab link feature in my other proposed patch?

romainj’s picture

Some example of standards routes:
- entity.entity_type.collection
- entity.entity_type.canonical
- entity.entity_type.edit_form
- entity.entity_type.delete_form
- entity.entity_type.add_form

I will try to have a look at your patch later on. Thanks for your help.

dunebl’s picture

Thanks for the list,
Regarding field collection, here is the results of my finding:

No changes:
entity.field_collection.edit_form => correctly named
entity.field_collection_item.field_ui_fields => correctly named
entity.entity_view_display.field_collection_item.default => doesn't exist

Ask for changes:
field_collection.overview_field_collections => entity.field_collection.collection
entity.field_collection_item.delete_form => entity.field_collection.delete_form

=>The add_form doesn't seems to be used in admin_toolbar

Do you think it is inline with your thoughts?
If you agree, I will create a patch for the field_collection module that will rename those routes.

romainj’s picture

I agree with #14. The add_form does not exist because the field collections are auto-created when you declare it on an entity.

adriancid’s picture

I see that we have here 3 commits related to the issue, but it is still open, this is fixed or need some work?

romainj’s picture

Status: Active » Closed (works as designed)