Problem/Motivation

FormStateInterface::cleanValues() method doc specifies @return $this, but FormState::cleanValues() doesn't return $this.

Proposed resolution

Fix it.

Remaining tasks

Reviews
Commit

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because that wasn't the intent
Issue priority Normal because it only happens when you try something like $form_state->cleanValues()->unsetValue($blah);. Your IDE says you can do it, but the code fails. This could be minor, but bugs can't be minor.
Unfrozen changes Not Unfrozen
Disruption Disruption is zero to none.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR queued form_state_clean_values.patch for re-testing.

almaudoh’s picture

Issue tags: +Quickfix

Marking quickfix to get some attention.

TR’s picture

Status: Needs review » Reviewed & tested by the community

This bit me several times.

A common use for this function would be $form_state->cleanValues()->getValues() to return an array of form state values with the Form API tokens etc. removed. As documented, that should work. But it does not because the implementation is faulty.

I checked the source and all the other method implementation in the FormState class return the proper documented types.

All methods declared by FormStateInterface are designed to be chainable, if appropriate. Setters, for example, always return $this, whereas getters obviously can't. cleanValues() simply modifies $form_state, so returning this is both appropriate and desired.

It's clear to me that FormStateInterface::cleanValues() was *intended* to return $this, and that the documentation that says it returns $this is not a mistake. Rather, the FormState implementation class is the place where the fault lies.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Let's test this.

almaudoh’s picture

Status: Needs work » Needs review
FileSize
676 bytes
1.01 KB

Tests added.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Looks good, thanks!

The last submitted patch, 5: form_state_clean_values-2388349-5-TEST-ONLY.patch, failed testing.

alexpott’s picture

Title: FormState::cleanValues() doesn't conform with the FormStateInterface documentation speci » FormState::cleanValues() doesn't conform with the FormStateInterface documentation
Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 89e6ec9 and pushed to 8.0.x. Thanks!

  • alexpott committed 89e6ec9 on 8.0.x
    Issue #2388349 by almaudoh: FormState::cleanValues() doesn't conform...

Status: Fixed » Closed (fixed)

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