Problem/Motivation

When looking at the API page information for the method processForm(), down below there's some inline docs about the condition that calls $form_state->isRebuilding() which doesn't make sense:


      // If $form_state->isRebuilding() has been set and input has been
      // processed without validation errors, we are in a multi-step workflow
      // that is not yet complete. A new $form needs to be constructed based on
      // the changes made to $form_state during this request. Normally, a submit
      // handler sets $form_state->isRebuilding() if a fully executed form
      // requires another step. However, for forms that have not been fully
      // executed (e.g., Ajax submissions triggered by non-buttons), there is no
      // submit handler to set $form_state->isRebuilding(). It would not make
      // sense to redisplay the identical form without an error for the user to
      // correct, so we also rebuild error-free non-executed forms, regardless
      // of $form_state->isRebuilding().
      // @todo Simplify this logic; considering Ajax and non-HTML front-ends,
      //   along with element-level #submit properties, it makes no sense to
      //   have divergent form execution based on whether the triggering element
      //   has #executes_submit_callback set to TRUE.
      if (($form_state->isRebuilding() || !$form_state->isExecuted()) && !FormState::hasAnyErrors()) {
        // Form building functions (e.g., self::handleInputElement()) may use
        // $form_state->isRebuilding() to determine if they are running in the
        // context of a rebuild, so ensure it is set.
        $form_state->setRebuild();
        $form = $this->rebuildForm($form_id, $form_state, $form);
      }
    }

Since you can't "set" a getter method with no parameters ($form_state->isRebuilding()), instead, the documentation needs to be changed to specify that if the form "rebuild" flag is set by calling the method $form_state->setRebuild(TRUE) and the input is processed without validation errors, then we are in a multi-step webform workflow that is not yet complete.

Steps to reproduce

Head to the function FormBuilder::processForm
API page information and look for the inline docs before the condition if (($form_state->isRebuilding() || !$form_state->isExecuted()) && !FormState::hasAnyErrors()) { ...

You can also see the inline docs in the file itself: core/lib/Drupal/Core/Form/FormBuilder.php, line 605

Proposed resolution

Change the inline docs in the core/lib/Drupal/Core/Form/FormBuilder.php file to better reflect the multi-step webform validation process.

Remaining tasks

The API pages need to be changed as well: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21Fo...

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Issue fork drupal-2776661

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joachim created an issue. See original summary.

pushpinderchauhan’s picture

Status: Active » Needs review
StatusFileSize
new1.38 KB
pushpinderchauhan’s picture

StatusFileSize
new2.2 KB

Just took care of line length and wrapping and updated the patch again. Please review.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.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.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.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.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.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.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.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.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative
+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -596,17 +596,17 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
-      // If $form_state->isRebuilding() has been set and input has been

It doesn't seem right to say that a method is set. This is actually getting the value of the $rebuild parameter. Why not just say that,
"If $form_state->rebuild has been set and input has been"

If that is correct there are other places in the comment it would need to change.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

ameymudras’s picture

StatusFileSize
new1.64 KB

Changes as per suggestion in #14

ameymudras’s picture

Status: Needs work » Needs review

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kristen pol’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Thanks for the update.

Nitpick: The comments need to be adjusted to be as close to 80 characters as possible.

  1. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -605,17 +605,17 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +      // If $form_state->rebuild has been set and input has been
    
  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -605,17 +605,17 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +      // handler sets $form_state->rebuild if a fully executed form
    
  3. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -605,17 +605,17 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
    +      // submit handler to set $form_state->rebuild. It would not make
    
ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new2.19 KB
vinmayiswamy’s picture

Verified and tested patch #21 in Drupal 10.1.x. 
Patch applied successfully.

Test Steps:
1. Fresh install Drupal 10.1.x.
2. Apply the given patch.
3. Navigate to /core/lib/Drupal/Core/Form/FormBuilder.php in the codebase to check '$form_state->rebuild' in processForm()

Test Result:

  • $form_state->rebuild is updated as suggested in #14 and
  • The comments are also adjusted to be as close to 80 characters as suggested in #20.

Thanks @ameymudras for the patch.

vinmayiswamy’s picture

Status: Needs review » Reviewed & tested by the community

Since the patch #21 is in green and has been addressed feedback from #14 and #20, changing issue status to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work

I don't think this an improvement, we're taking an awkwardly phrased comment about an API method and making it about a protected property instead. What about 'If $form_state->isRebuilding() returns TRUE" at least for the first part of the comment.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Needs review

Changed to use a phrase of the form, "'rebuild' has been set to TRUE", which is from the docs for \Drupal\Core\Form\FormState::$rebuild.

joachim’s picture

Title: incorrect uses of isRebuilding() in inline does in processForm() » incorrect uses of isRebuilding() in inline docs in processForm()
Status: Needs review » Needs work

> I don't think this an improvement, we're taking an awkwardly phrased comment about an API method and making it about a protected property instead.

Agreed -- the protected property is internal.

> If 'rebuild' has been set to TRUE

This doesn't help either. How do I find out more about what 'rebuild' is and how to set it or check for it?

> What about 'If $form_state->isRebuilding() returns TRUE" at least for the first part of the comment.

Maybe. It depends whether the reader of this documentation is trying to know

A. 'how do I know which behaviour I will get here' --> isRebuilding() is the key thing because that's how you find out
B. 'how do I influence which behaviour I will get here' --> isRebuilding() is one step removed from this AND its docs don't tell you how to change that status, and what you actually need to know about is setRebuild()

I'd lean towards B.

brandonlira made their first commit to this issue’s fork.

brandonlira’s picture

Status: Needs work » Needs review

Hi,
I’ve updated the inline documentation in processForm() (in FormBuilder.php) to clarify the usage of isRebuilding() and setRebuild(). The changes now specify that isRebuilding() is a getter that returns TRUE when the rebuild flag is set (via setRebuild(TRUE)), rather than implying that it can be directly set.

I hope this addresses the feedback from earlier comments. Please review my changes in MR ![!9319] and let me know if further adjustments are needed.

sivaji_ganesh_jojodae’s picture

joachim’s picture

Status: Needs review » Needs work

> // If $form_state->isRebuilding() returns TRUE and input has been processed

This is correct and accurate, but from the POV of DX, it doesn't fix the problem.

The original docs approach this from answering the question, 'what do you need to do to the form to get this behaviour?'

> If $form_state->isRebuilding() has been set

It's just that the technical detail is wrong.

We need to change the detail, not the meaning being conveyed.

charlliequadros’s picture

Hi @joachim,
it's not clear what the comment is meant to convey. To me, it should include something like:

// If $form_state->isRebuilding() was set by $form_state->setRebuild() and the input was
// processed without validation errors, we are in a multi-step workflow

This would help clarify when and why the rebuild happens. What do you think?

charlliequadros’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.51 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

brandonlira’s picture

Status: Needs work » Needs review

Hi @joachim,

I’ve updated the comment to reflect that setRebuild(TRUE) is what triggers the behavior, as you suggested, while preserving the original intention of explaining how to get this behavior from a DX perspective.

I also rebased the branch onto the latest 11.x since it was many commits behind, to ensure the pipeline runs accurately.

Let me know if anything else needs adjusting!

smustgrave’s picture

Status: Needs review » Needs work

For good practice issue summary should be complete using standard template.

danrod’s picture

Issue summary: View changes
danrod’s picture

I changed the summary above using the standard template, hope it makes sense.

danrod’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback believe to be addressed

  • catch committed 09c82bf0 on 11.2.x
    Issue #2776661 by brandonlira, ameymudras, er.pushpinderrana, quietone,...

  • catch committed 9dd9b391 on 11.x
    Issue #2776661 by brandonlira, ameymudras, er.pushpinderrana, quietone,...
catch’s picture

Version: 11.x-dev » 11.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.2.x, thanks!

Status: Fixed » Closed (fixed)

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