Updated: Comment #0

Problem/Motivation

Follow-up from #2112807-32: Move the form builder functions in form.inc to a form service. 18. (see also comment #33)
form_options_flatten() also needs to be a method, it slipped through the cracks of the conversion.

Proposed resolution

Convert form_options_flatten() to FormBuilder::flattenOptions()

Remaining tasks

N/A

User interface changes

N/A

API changes

API addition, wrapper is left in place

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Active » Needs review
FileSize
7.69 KB
tim.plunkett’s picture

Issue tags: +PHPUnit, +FormInterface

.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -1647,6 +1654,45 @@ public function setValue($element, $value, &$form_state) {
+  /**
+   * Iterates over an array and returns a flat array with duplicate keys removed.
+   *
+   * This function also handles cases where objects are passed as array values.
+   */
+  protected function doFlattenOptions($array) {

Should we also document the @param @return here?

tim.plunkett’s picture

FileSize
2.93 KB
7.28 KB

While trying to document doFlattenOptions(), I realized its return signature was inconsistent, so I cleaned that up.
Also rewrapped some docs to 80 chars.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -1656,29 +1656,23 @@ public function setValue($element, $value, &$form_state) {
+   * Iterates over an array returning a flat array with duplicate keys removed.

Well ... we don't really return anything.

tim.plunkett’s picture

FileSize
562 bytes
7.28 KB

Ahh very good point.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

damiankloip’s picture

+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -125,6 +125,13 @@ class FormBuilder implements FormBuilderInterface {
+  protected $flattenedOptions = array();

@@ -1649,6 +1656,37 @@ public function setValue($element, $value, &$form_state) {
+    $this->flattenedOptions = array();
...
+  protected function doFlattenOptions(array $array) {
...
+        $this->flattenedOptions[$key] = 1;

Just putting it out there, instead of essentially storing state on the form builder server, could we pass the flattened options as a second parameter? this could be passed recursively etc... no problem.

Let me know if I'm talking shit.

damiankloip’s picture

Issue summary: View changes

listed which number followup this was

tim.plunkett’s picture

6: form-2120841-6.patch queued for re-testing.

Xano’s picture

6: form-2120841-6.patch queued for re-testing.

smiletrl’s picture

webchick’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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