NestedArray filter doesn't clear empty multidimensional arrays

Created on 17 August 2023, 10 months ago

Problem/Motivation

When I have a multidimensional array with empty values, only the last children have the filter callable applied because the filter callable is applied before the children are evaluated.

$array = [
  'first' => ['', '', ''],
  'second => [
    ['', ''],
    '',
  ],
  'third' => [],
];

NestedArray::filter($array)

This will result in the following array:

$array = [
  'first' => [],
  'second => [
    [],
  ]
];

I would expect empty parents to also have the filter callable applied. Which would result in an empty array returned for the above.

The reason for needing this is for handling the data from structured / #tree forms where the data is empty.

Steps to reproduce

Run the code example above.

Proposed resolution

Run the callable after iterating over the children elements.

Remaining tasks

Identify whether this is intentional behaviour (there don't appear to be any uses other than in test for this function).

API changes

Breaking changes to the way multidimensional arrays are filtered.

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
BaseΒ  β†’

Last updated about 1 hour ago

Created by

πŸ‡¬πŸ‡§United Kingdom kalpaitch

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

Comments & Activities

Production build 0.69.0 2024