Skip to content

Fix falsy value check dropping 0/false in field collection sub-fields - #2026

Open
jcPimcore wants to merge 3 commits into
2026.2from
fix/PEES-1279-field-collection-default-value
Open

Fix falsy value check dropping 0/false in field collection sub-fields#2026
jcPimcore wants to merge 3 commits into
2026.2from
fix/PEES-1279-field-collection-default-value

Conversation

@jcPimcore

@jcPimcore jcPimcore commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • FieldCollectionsAdapter::processCollectionRaw() used !$elementValue to decide whether a field-collection sub-field had a submitted value.
  • That's true for 0, false, "", "0" in PHP, so any such legitimate value submitted for a field-collection sub-field (including a pre-filled numeric default of 0) was silently dropped before it ever reached the field's own setter adapter.
  • Changed the guard to $elementValue === null, so a genuinely absent field is still skipped, but falsy-but-real values are kept.

Test plan

  • Added tests/Unit/DataObject/Data/Adapter/FieldCollectionsAdapterTest.php, calling processCollectionRaw() via reflection with a real Fieldcollection\Definition registered in RuntimeCache.
  • Ran the suite locally: all 4 new tests pass against the fix, and I confirmed 3 of them fail against the pre-fix code (temporarily reverted the fix, reran, confirmed failures, then restored it) — verified regression test.

Refs PEES-1279
Resolves https://github.com/pimcore/service-operations/issues/953

🤖 Generated with Claude Code

jcPimcore and others added 2 commits September 3, 2026 12:04
FieldCollectionsAdapter::processCollectionRaw() used !$elementValue to
decide whether a field-collection sub-field had a value, which is true
for 0, false, "0" and "" in PHP. This silently dropped legitimate
falsy values (e.g. a numeric field's default value of 0) before they
ever reached the field's setter adapter.

Refs PEES-1279

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Covers processCollectionRaw() keeping 0, false and "" values instead
of dropping them, while still skipping a genuinely absent field.
Verified this test fails against the pre-fix code and passes against
the fix.

Refs PEES-1279

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings September 3, 2026 13:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Present null values must reach the setter adapter so fields can be explicitly cleared.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes field-collection handling of submitted falsy values.

Changes:

  • Preserves 0, false, and empty strings.
  • Adds regression tests for falsy and missing values.
File summaries
File Description
tests/Unit/DataObject/Data/Adapter/FieldCollectionsAdapterTest.php Adds regression coverage for falsy and missing values.
src/DataObject/Data/Adapter/FieldCollectionsAdapter.php Preserves falsy values, but still treats an explicit null like an omitted key.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/DataObject/Data/Adapter/FieldCollectionsAdapter.php Outdated
@jcPimcore jcPimcore self-assigned this Sep 3, 2026
@jcPimcore jcPimcore added this to the 2026.2.9 milestone Sep 3, 2026
@jcPimcore
jcPimcore force-pushed the fix/PEES-1279-field-collection-default-value branch from aec33b0 to e8ff1c1 Compare September 3, 2026 14:06
processCollectionRaw() still conflated an omitted key with a key
explicitly submitted as null, since both produced $elementValue ===
null. The setter-adapter contract allows null to clear a field on
non-patch saves, so a field-collection sub-field could still never be
cleared. Check key presence with array_key_exists(), matching the
existing pattern in ObjectBricksAdapter::getCollectionData(), and pass
a present null through to the adapter.

Adds regression tests for both the explicit-null-passthrough case and
a collection item with no 'data' key at all. Ran the full
tests/Unit/DataObject/ suite locally (43 tests, 93 assertions) with no
regressions.

Addresses Copilot review feedback on PR #2026.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jcPimcore

Copy link
Copy Markdown
Contributor Author

Good catch — fixed in ebfc3e8:

  • processCollectionRaw() now checks array_key_exists($elementName, $blockElement) instead of testing the value for null, matching the existing pattern in ObjectBricksAdapter::getCollectionData(). A present null now reaches the setter adapter (so a field-collection sub-field can be cleared on non-patch saves), while a genuinely absent key is still skipped.
  • Added a guard for $blockElement not being an array at all (no data key on the collection item), so that case doesn't get misread as "every field explicitly null".
  • Added regression tests for both: explicit-null-passthrough, and a collection item with no data key.
  • Ran the full tests/Unit/DataObject/ suite locally — 43 tests, 93 assertions, no regressions.

🤖 Generated with Claude Code

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix is focused, regression-tested, and has no unresolved issues.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants