form_alter runs on Confirm Forms and causes AJAX errors

Created on 12 February 2025, 4 months ago

Problem/Motivation

When using Content Lock with e.g. the Trash module, an AJAX error appears on certain Confirm Forms:

The "entity" parameter was not converted for the path "/admin/lock/create/node/{entity}/{langcode}/{form_op}" (route name: "content_lock.create_lock.node")

I think this is not an issue of the mentioned Trash module, but has to do with when the "drupal.content_lock.lock_form" library is applied inside the form_alter hook.

Steps to reproduce

  1. Install Content Lock and the Trash module https://www.drupal.org/project/trash .
  2. Move a node to the trash.
  3. Restore the node.
  4. The error appears on the confirm form.

Proposed resolution

I've included a patch file with a solution: A check that the current form is NOT of ConfirmFormInterface. This works for my use-case right now, but I think a better solution would be to more clearly define what exact forms should be altered in the hook.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇳🇱Netherlands perryjanssen

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

Merge Requests

Comments & Activities

  • Issue created by @perryjanssen
  • 🇳🇱Netherlands perryjanssen

    Attached patch

  • First commit to issue fork.
  • Pipeline finished with Failed
    4 months ago
    Total: 237s
    #422137
  • Pipeline finished with Failed
    4 months ago
    Total: 253s
    #422138
  • 🇮🇳India arunsahijpal

    Hi @perryjanssen,
    This solution is working fine for me as ConfirmFormInterface do not require entity locking since they do not modify entity data directly.
    Attaching ss for reference.

    But we would like to here best solution from @alexpott

    Thanks

  • I've tried to reproduce this issue usnig given steps to reproduce but could not able to do it.
    I think this issue is fixed in the latest release of trash module. So we should close this ticket.

  • Status changed to Needs work 2 days ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    This is still an issue - I've improved the steps to reproduce in the issue summary.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    I've added a test to prove the bug and prove the MR fixes the error.

    I'm still think about whether the fix is correct. I think it might be. Will discuss with other maintainers.

Production build 0.71.5 2024