The documentation for hook_form_alter() contains this description for $form_id.

$form_id: String representing the name of the form itself. Typically this is the name of the function that generated the form.

That's true in Drupal 7. In Drupal 8, where forms are implemented by classes, the form ID is simply the value returned by its getFormId() method.

The documentation should be updated to reflect this, including what reported in hook_form_FORM_ID_alter() and hook_form_BASE_FORM_ID_alter().

Comments

eojthebrave created an issue. See original summary.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

Issue tags: +Novice, +Bug Smash Initiative
avpaderno’s picture

Title: Update documentation for $form_id parameter on hook_form_alter() and variations » Update the description given for $form_id
Issue summary: View changes

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anjali rathod’s picture

Assigned: Unassigned » anjali rathod
anjali rathod’s picture

Assigned: anjali rathod » Unassigned
Status: Active » Needs review
StatusFileSize
new746 bytes

Updated the $form_id description for hook_form_alter() .

pooja saraah’s picture

StatusFileSize
new740 bytes
new575 bytes

Fixed failed commands on #11
Attached interdiff patch against Drupal 9.5.x

vinmayiswamy’s picture

I verified patch #12 in Drupal 9.4.x version. Patch applied cleanly and updated the $form_id description for hook_form_alter()
Thanks @pooja saraah

anjali rathod’s picture

Status: Needs review » Reviewed & tested by the community
avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
- *   String representing the name of the form itself. Typically this is the
- *   name of the function that generated the form.
+ *   A string that is the unique ID of the form, getFormId() method is used to
+ *   set it.
  *
  * @see hook_form_BASE_FORM_ID_alter()
  * @see hook_form_FORM_ID_alter()

That is a comma-split sentence: They are two sentences merged together with a comma, when the correct punctuation is a period.
There is no need to say method; that is clear, especially when the method name is prefixed by the class name that implements it (or the name of the interface that defines it). In this case, the method is defined from an interface, and the method name is Drupal\Core\Form\FormInterface::getFormId().

A string that is the unique ID of the form. Drupal\Core\Form\FormInterface::getFormId() is used to set it.

Alternatively, the comment could say:

A string that is the unique ID of the form, set by Drupal\Core\Form\FormInterface::getFormId().

I prefer the latter.

anjali rathod’s picture

Status: Needs work » Needs review
StatusFileSize
new760 bytes
hlopez’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and tested patch #16 in Drupal 9.4.x. Looks good!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: updated-the-comment-2939237-16.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Putting back to RTBC that failure appeared random

  • catch committed bf7d238 on 10.0.x
    Issue #2939237 by Anjali Rathod, pooja saraah, apaderno, eojthebrave:...
  • catch committed 96a199b on 10.1.x
    Issue #2939237 by Anjali Rathod, pooja saraah, apaderno, eojthebrave:...
  • catch committed 6d469d9 on 9.4.x
    Issue #2939237 by Anjali Rathod, pooja saraah, apaderno, eojthebrave:...
  • catch committed 818ac70 on 9.5.x
    Issue #2939237 by Anjali Rathod, pooja saraah, apaderno, eojthebrave:...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x and cherry-picked back to 9.4.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.