addCleanValueKey() accepts string but supports array

Created on 15 November 2022, about 2 years ago
Updated 28 September 2024, about 2 months ago

Problem/Motivation

ForStateInterface interface has a addCleanValueKey() method that allows to "Adds a key to the array of form values that will be cleaned."

The method documentation states that it accepts a string. However, when an array of form keys with their parents is passed - the cleanValues() method correctly handles such keys, which is great for the cases where we need to ignore values at depth.

Steps to reproduce

  1. Create a parent element 'fieldname' with '#tree' => TRUE and add a sub-element 'sub_fieldname' to, say, config form.
  2. Save the form and observe that 'sub_fieldname' is now saved to the form_state and is not removed.
  3. Add a #process callback with code $form_state->addCleanValueKey(['fieldname', 'sub_fieldname']);
  4. Save the form and observe that 'sub_fieldname' is now correctly removed. This demonstrates that both strings and array keys, rather than just string keys, can be passed to addCleanValueKey() method.


<h3 id="summary-proposed-resolution">Proposed resolution</h3>
Update documentation in FormStateInterface interface to specify an argument as string or array.

<code>
  /**
   * Adds a key to the array of form values that will be cleaned.
   *
   * @param string|array $key
   *   The form value key or an array of key with parents to be cleaned.
   *
   * @return $this
   */
  public function addCleanValueKey($key);

Remaining tasks

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

none

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

forms system

Created by

🇦🇺Australia alex.skrypnyk Melbourne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024