latest_version form state redirect assumes route parameters

Created on 25 September 2020, over 4 years ago
Updated 27 April 2023, over 1 year ago

Problem/Motivation

While working with a custom entity I noticed that content moderation EntityTypeInfo::bundleFormRedirect() makes an assumption regarding the parameters to pass to an entity's latest-version route. The assumption made is that the only parameter is the ID of the entity. In my use case, I have a custom entity (registrant) which directly relates to another entity (event) and the route structure is as follows:

/events/{event}/registrations/{registrant}

For example:

/events/123/registrations/10

The latest-version route automatically created by content moderation creates a route (entity.registrant.latest-version) which is based upon the canonical route for that entity, and adds '/latest' to the end, which forms a path as follows:

/events/{event}/registrations/{registrant}/latest

The problem is that EntityTypeInfo::bundleFormRedirect() assumes that all entity latest-version paths will be similar to those of nodes, such as:

/node/123/latest

So when it runs the following

$form_state->setRedirect("entity.$entity_type_id.latest_version", [$entity_type_id => $entity->id()]);

For a node this would work fine, but my paths require another route parameter.

Steps to reproduce

* Create a custom entity with a multi-variable canonical route URL containing more than one parameter.
* Enable content moderation and workflow for that entity
* Create a non-published (draft by default) revision of that entity
* You will see the following error:

Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("registrant") to generate a URL for route "entity.registrant.latest_version".

Proposed resolution

Given that bundleFormRedirect() has access to the entity to generate the redirect, it could use the entities 'toUrl()' method to generate the latest-version Url object and switch to using setRedirectUrl() instead of setRedirect() on the form state.

Remaining tasks

Write tests?

User interface changes

None

API changes

None?

Data model changes

None

Release notes snippet

Fix latest-version form state redirect URL for entities with hierarchical route paths

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Content moderationΒ  β†’

Last updated 24 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΊAustralia @Sam152
Created by

πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024