Some mandatory parameters are missing to generate clone form URL

Created on 23 August 2023, over 1 year ago
Updated 5 September 2024, 4 months ago

Problem/Motivation

When trying to clone entities with no canonical path, I got this error :
Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("xxxx_xxx") to generate a URL for route "entity.xxxx_xxx.edit_form". in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 181 of core/lib/Drupal/Core/Routing/UrlGenerator.php).
This come from a parameter required in the edit form template link and this parameter is not the id of the cloned entity.

Steps to reproduce

This error can be reproduced by cloning an entity with no canonical path and multiple parameters in the edit_form template link.
For example, the commerce_product_variation entity from Commerce module can cause this error because the edit-form template link is :
/product/{commerce_product}/variations/{commerce_product_variation}/edit
where {commerce_product} is the missing parameter.

Proposed resolution

The line that causes the error is the line 72 of the DynamicLocalTasks class that defines the base route of the local task :
'base_route' => "entity.$entity_type_id." . ($has_canonical_path ? "canonical" : "edit_form")
But I don't know what to do to solve the problem, should we pass the needed parameter to route and how to do that ?

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇫🇷France solene_ggd

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @solene_ggd
  • Status changed to Needs work over 1 year ago
  • 🇫🇷France solene_ggd

    Ok, I found that using 'canonical' or 'edit-form' link template for the 'clone-form' link template, instead of always /entity_clone/$entity_type_id/{{$entity_type_id}}", fixes the issue. I use the same logic than in the DynamicLocalTasks by using the 'canonical' link template if it exists, and the 'edit-form' link template otherwives.
    It is a major change in the module because it changes all entity clone form paths, but I didn't find another solution.
    Here is a patch including the fix in the .module file, but tests are failing. Another patch is coming soon for that.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    30 pass
  • 🇫🇷France solene_ggd

    Here is a patch including changes in tests. It is a big patch, all tests are affected because the entity clone form path has to be found dynamically now. We can't do anything else, I think, because the 'clone-form' link template is now depending on path defined in other modules.

  • 🇮🇳India rajeshreeputra Pune

    Can we get quick MR for ease of review and merge.

  • Assigned to nicolasgraph
  • Status changed to Needs work 5 months ago
  • 🇫🇷France nicolasgraph Strasbourg

    I'm working on the MR.

  • Issue was unassigned.
  • Status changed to Needs review 4 months ago
  • 🇫🇷France nicolasgraph Strasbourg

    The MR should be ready to go.

  • Pipeline finished with Failed
    4 months ago
    Total: 233s
    #274478
Production build 0.71.5 2024