Skip to content

Commit

Permalink
tweak when the block is considered empty
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Oct 9, 2024
1 parent 88f7d02 commit f1828dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit f1828dc

Please sign in to comment.