Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When using hook_FORM_ID_alter(), with FORM_ID = menu_link_form or FORM_ID = menu_form (at least, maybe others as well), the form_alter hook is called twice (I'm wondering if it's because in these cases, FORM_ID = BASE_FORM_ID).
As a side note, when debugging the form, the class attribute contains two 'menu-form' (or 'menu_link_form') classes, and the '#theme' array contains twice the same key either.
Comments
Comment #1
Simon Georges CreditAttribution: Simon Georges commentedI've found #1768526: NodeFormController::validate() calls buildEntity() twice as a similar (or not?) issue...
Comment #10
quietone CreditAttribution: quietone as a volunteer commented@Simon Georges, Thank you for reporting this problem. We rely on issue reports like this to improve Drupal core.
I tested this on 9.3.x and was not able to reproduce this error. I created a test module and adding the hooks, setting breakpoints on menu forms. I tested adding a menu, editing a menu and the same for menu links. The hooks were not executing twice.
Therefore, closing as cannot reproduce. If you are experiencing this problem reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!