incorrect uses of isRebuilding() in inline does in processForm()

Created on 1 August 2016, over 8 years ago
Updated 25 August 2024, 7 months ago

API page: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilder....

      // 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().

You can't set isRebuilding(). It's a getter method with no parameters. You set setRebuild(). So the first 3 mentions of this should be changed to setRebuild().

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Documentation 

Last updated 4 days ago

No maintainer
Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • @quietone opened merge request.
  • Status changed to Needs review 7 months ago
  • 🇳🇿New Zealand quietone

    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.

  • Status changed to Needs work 7 months ago
  • 🇬🇧United Kingdom joachim

    > 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.

  • First commit to issue fork.
  • 🇧🇷Brazil brandonlira

    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.

  • 🇬🇧United Kingdom joachim

    > // 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.

  • 🇧🇷Brazil charlliequadros

    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
    // that is not yet complete. In this case, a new $form needs to be constructed based on
    // the changes made to $form_state during the request.
    
    
Production build 0.71.5 2024