Problem/Motivation

API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21Fo...

For the following methods:
- setStorage
- getStorage
- get
- set
- has

Change doc comments from

"Sets a value to an arbitrary property."

to a more descriptive comments, and say that it sets the form state storage.

Add @see references between all of the following methods:
- setStorage
- getStorage
- get
- set
- has

Steps to reproduce

Proposed resolution

Remaining tasks

Update patch
Respond to #34
review
commit

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

hershey.k’s picture

Status: Active » Needs review
FileSize
643 bytes

Does the applied description add enough clarity?

Status: Needs review » Needs work

The last submitted patch, 2: formstate_set_should-2714753-2.patch, failed testing.

hershey.k’s picture

Status: Needs work » Needs review

The test result failure seems to be unrelated to the patch provided. The patch needs to be re-tested.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! This is a good start, but it still needs some work:

  1. +++ b/core/lib/Drupal/Core/Form/FormStateInterface.php
    @@ -192,7 +192,9 @@ public function &getStorage();
    +   * Sets a value to an arbitrary property which saves it to the form state storage.
    

    This line goes over 80 characters. The first line of a function doc block needs to be a one-line description of less than 80 chars.

  2. +++ b/core/lib/Drupal/Core/Form/FormStateInterface.php
    @@ -192,7 +192,9 @@ public function &getStorage();
    +   * @see FormState::getStorage()
    

    @see goes at the end of a doc block, not in the middle. See https://www.drupal.org/node/1354#order

    But in any case, we should not be doing an @see to FormState::getStorage, but rather to FormStateInterface::getStorage().

    Also it needs the full namespace.

    Also we need an @see on getStorage to this method. And all related methods should also be linked in this way.

snehi’s picture

Status: Needs work » Needs review
FileSize
905 bytes
823 bytes

Done as said by Jhodgdon.

jhodgdon’s picture

Title: FormState::set() should explain it works with storage, and crosslinked with getStorage() » FormState::set(), get(), and has() should explain they work with storage, and crosslinked with getStorage()
Status: Needs review » Needs work

Good, but not complete... We should have @see references between all of the following methods, I think:
- setStorage
- getStorage
- get
- set
- has

They all work with the storage. We should also update the get() and has() methods in a similar way to what set() has in this patch (to say in the first line that they work with the storage).

But I also think we need to make sure that the terminology is consistent between getStorage(), setStorage(), get(), set(), and has(). Currently, in this patch, set() says "Sets value to an arbitrary property and saves it to the form state storage." What I think it should probably say is more like "Sets a value for a property in the form state storage." ("a value to an arbitrary property" doesn't really make sense to me). And then all the other 4 methods should use that same terminology.

Come to think of it, I am not sure the @param $property description on get(), set(), and has() actually makes much sense either. They are on an interface, but they reference $storage, which is not defined on the interface so doesn't really exist. This should also be fixed, so that it talks about the "form state storage" rather than $storage.

ashishdalvi’s picture

Assigned: Unassigned » ashishdalvi
ashishdalvi’s picture

Assigned: ashishdalvi » Unassigned

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.

mradcliffe’s picture

Adding tag for sprints on Friday. The patch needs work to address the comments above.

Finn Lewis’s picture

I'm taking a look at this at Drupalcon Dublin

Finn Lewis’s picture

Assigned: Unassigned » Finn Lewis
Finn Lewis’s picture

Hi @jhodgdon,

reviewing your comments on #7, I've uploaded a patch that cross references setStorage, getStorage, get, set, has with @see comments for each . Is this what you meant?

On the following comment:
This should also be fixed, so that it talks about the "form state storage" rather than $storage

I've discussed with one of the sprint mentors, and wanted to check this. setStorage does refer to the $storage array, and getStorage returns this array, so could you clarify why we shouldn't refer to $storage?

Many thanks,

Finn

Finn Lewis’s picture

Assigned: Finn Lewis » Unassigned

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.

dark-o’s picture

Assigned: Unassigned » dark-o
Issue tags: +SprintWeekend2018

I am now looking at this issue

dark-o’s picture

Status: Needs work » Needs review

Patch that Finn provided works OK, comments are rectified as requested. Setting this issue to "review" to see if it will pass tests.

dark-o’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated the description of the issue to reflect all the changes as advised in the comment #7

Removed "Needs issue summary update" tag

dark-o’s picture

Hiding patches #6 and #2 as patch #14 includes the code of the former two patches

dark-o’s picture

Assigned: dark-o » Unassigned

Unassigning from me as I have been explained by my mentor that we should use comments rather that assigning issue to us. I am still working on this issue

dark-o’s picture

Status: Needs review » Reviewed & tested by the community

Test have now passed for both php 5 and 7 on 8.6.x branch

dark-o’s picture

setting to "Reviewed & tested by the community"

eojthebrave’s picture

Status: Reviewed & tested by the community » Needs work

Hey @dark-o thanks for working on this.

+++ b/core/lib/Drupal/Core/Form/FormStateInterface.php
@@ -173,11 +178,16 @@ public function setStorage(array $storage);
+ * Gets a value for a property in the form state storage.

I think "Gets the value" reads better than "Gets a value" (same for "Sets the value") but that might also just be overly nit-picky so fine by me if you don't agree. Just thought I would point it out.

I think we should also update the docblock for \Drupal\Core\Form\FormState::$storage as well. It currently reads:

  /**
   * This is not a special key, and no specific support is provided for it in
   * the Form API. By tradition it was the location where application-specific
   * data was stored for communication between the submit, validation, and form
   * builder functions, especially in a multi-step-style form. Form
   * implementations may use any key(s) within $form_state (other than the keys
   * listed here and other reserved ones used by Form API internals) for this
   * kind of storage. The recommended way to ensure that the chosen key doesn't
   * conflict with ones used by the Form API or other modules is to use the
   * module name as the key name or a prefix for the key name. For example, the
   * entity form classes use $this->entity in entity forms, or
   * $form_state->getFormObject()->getEntity() outside the controller, to store
   * information about the entity being edited, and this information stays
   * available across successive clicks of the "Preview" button (if available)
   * as well as when the "Save" button is finally clicked.
   *
   * @var array
   */
  protected $storage = [];

But, this isn't really accurate anymore. As the rest of the changes in this issue show we now have get/set/has methods that are part of the API and work exclusively with this variable.

neerajsingh’s picture

Assigned: Unassigned » neerajsingh
neerajsingh’s picture

Status: Needs work » Needs review
FileSize
3.13 KB
606 bytes

suggestion on

"Gets the value" reads better than "Gets a value"

looks good to me, hence re-rolled the patch from #14.

neerajsingh’s picture

Assigned: neerajsingh » Unassigned
neerajsingh’s picture

Assigned: Unassigned » neerajsingh
Status: Needs review » Needs work

My bad, I just updated for 'Gets' and missed out the 'Sets', will update the patch and re-roll the same.

neerajsingh’s picture

Assigned: neerajsingh » Unassigned
Status: Needs work » Needs review
FileSize
3.13 KB
595 bytes
mradcliffe’s picture

If anyone wants to review this issue we should make sure that the @neerajsingh's patch in #31 addresses @eojthebrave's comments and update the issue summary to indicate the proposed resolution of reviewed patch as well as any info. that a core committer might need to know while evaluating the issue.

benjifisher’s picture

Issue tags: +Nashville2018
eojthebrave’s picture

Status: Needs review » Needs work

I think we still need to get the text for

\Drupal\Core\Form\FormState::$storage

updated. This text for example, is no longer true: "This is not a special key, and no specific support is provided for it in the Form API."

And then there's a bunch of maybe useful, maybe not, details about making keys unique. I would argue this could probably be removed since I believe just using these methods, and $storage, is the recommended best-practice now. But, I don't know that for sure. :/

I think updating the text to something like:

Storage for application specific information and communication between the submit, validation, and form builder functions, especially in a multi-step-style form. This data should be accessed using the related getter/setter methods.

And then @see those.

I'm around at the Sprint in Nashville if anyone is working on this today.

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.

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.

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.

quietone’s picture

Reviewed at a documentation triage meeting.

The changes in the patch are still valid but it needs a reroll. The issue summary is out of date,. Adding tags. This is suitable for a novice, leaving that tag.

ankit_rathore’s picture

Status: Needs work » Needs review
FileSize
5.09 KB
2.05 KB

Re-rolled patch #31 against 10.1.x-dev
Please review it.

joachim’s picture

Status: Needs review » Needs work

The docs changes look good, but this patch has los of unrelated changes - lots of code changes and this docs change:

+++ b/core/lib/Drupal/Core/Form/FormStateInterface.php
@@ -117,7 +117,7 @@ public function getResponse();
-   *   The name of the route
+   *   The name of the route.

These need to be removed.

ankit_rathore’s picture

FileSize
4.69 KB
1.72 KB

ignore this comment

ankit_rathore’s picture

Status: Needs work » Needs review
FileSize
4.69 KB
1.72 KB

I have considered the above suggestions and incorporated the changes in this patch.

joachim’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Form/FormStateInterface.php
@@ -438,29 +463,29 @@ public static function hasAnyErrors();
-   *   $form['actions']['previous'] = array(
+   *   $form['actions']['previous'] = [
    *     '#type' => 'submit',
    *     '#value' => t('Previous'),
-   *     '#limit_validation_errors' => array(),       // No validation.
-   *     '#submit' => array('some_submit_function'),  // #submit required.
-   *   );
+   *     '#limit_validation_errors' => [],       // No validation.
+   *     '#submit' => ['some_submit_function'],  // #submit required.
+   *   ];
    * @endcode

There are still all these code changes.

ankit_rathore’s picture

Status: Needs work » Needs review
FileSize
3.15 KB

Those were changes suggested by the code snipper uploading another patch by removing those changes.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

LGTM.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x, thanks!

  • catch committed 237373bc on 10.1.x
    Issue #2714753 by ankit.rathore1, neerajsingh, snehi, Finn Lewis, hershy...

Status: Fixed » Closed (fixed)

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