The problem

There are a few places in the current entity system where undocumented, hard-coded assumptions are being made.

These assumptions kick in when entities try to dynamically load routes, provide placeholders for them or generate URLs with them. Although they work 90% of the time, the other 10% they cause a hard crash because of route dependencies not being met.

Where it occurs

I've tackled each issue separately, but both would require an additional signature on the entity interface:

How it can crash a website

The following scenarios currently cause a crash until the above two issue are fixed:

  • Any entity not naming its routes entity.{entity type}.{link template}. For instance mymodule.{entity type}.{link template} would sometimes crash.
  • Any entity having more than one placeholder in its Field UI routes. For instance /admin/%my_context_entity/configure/%my_content_entity/fields will always crash. The workaround is to create a route /admin/%my_content_entity/fields and create a breadcrumb generator to make up for the lost breadcrumb info.
  • Probably some other places I haven't come across yet.

Proposed resolution

Review both patches and commit them to either 8.0.x (preferred) or 8.1.x as currently, having an incomplete system which can crash your site in edge cases just doesn't feel right to a module developer.

Although both issues implement new methods on the entity interface and thus break BC in some way, the fallout is limited: In core only Views does not extend the base entity class and thus needed updating (see patches in related issues). In contrib it's highly unlikely, yet not impossible, that a module developer decided not to extend from the base entity class.

Comments

kristiaanvandeneynde created an issue. See original summary.

kristiaanvandeneynde’s picture

Title: [Meta] Expose entity route/url logic instead of hardcoding it » [Meta] Expose entity route/url logic instead of hard-coding it
kristiaanvandeneynde’s picture

Status: Needs review » Closed (duplicate)

Closing this as #2645136: Clearly document the expected route name pattern for entities can be solved with a protected method and then calling $entity->toUrl()->getRouteName() as mentioned by tstoeckler in #18

So the remaining discussion can take place in #2651974: field_ui_entity_operation() cannot respect route parameters because of incorrectly named routes