Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak when the block is considered empty #1529

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@ public function parseField(): mixed
$index = 1;
$resultBlocks = [];
foreach ($expanded as $blockData) {
// all the fields are empty and setEmptyValues is off, ignore the block
// if all the fields are empty and setEmptyValues is off, ignore the block
if (
!empty(array_filter(
$blockData['fields'],
fn($value) => (is_string($value) && !empty($value)) || (is_array($value) && !empty(array_filter($value)))
fn($value) => (
(is_string($value) && !empty($value)) ||
(is_array($value) && !empty(array_filter($value))) ||
is_bool($value) ||
is_numeric($value)
)
))
) {
$resultBlocks['new' . $index++] = $blockData;
Expand Down
8 changes: 7 additions & 1 deletion src/fields/SuperTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ public function parseField(): mixed
$preppedData[$blockIndex . '.enabled'] = true;
$preppedData[$blockIndex . '.fields.' . $subFieldHandle] = $value;

if ((is_string($value) && !empty($value)) || (is_array($value) && !empty(array_filter($value)))) {
// if all the fields are empty and setEmptyValues is off, ignore the block
if (
(is_string($value) && !empty($value)) ||
(is_array($value) && !empty(array_filter($value))) ||
is_bool($value) ||
is_numeric($value)
) {
$allEmpty = false;
}

Expand Down
Loading