Skip to content

Fix array-to-string conversion in ThemeConfig - #33

Open
ImanuelBertrand wants to merge 2 commits into
mage-os:mainfrom
ImanuelBertrand:fix/theme-config-array-to-string
Open

ImanuelBertrand wants to merge 2 commits into
mage-os:mainfrom
ImanuelBertrand:fix/theme-config-array-to-string

Conversation

@ImanuelBertrand

@ImanuelBertrand ImanuelBertrand commented Sep 11, 2026 •

Copy link
Copy Markdown

ThemeConfig::normalizeValue() cast values with (string), so array values from the design config form (image uploader fields like favicon and logos post a list of file descriptors) triggered an "Array to string conversion" warning and normalized to the literal "Array" — making every such field look unchanged, or changed to the same useless value.

Arrays are now flattened instead: a list of file descriptors is reduced to its file values (the stored config value, as set by Theme\Model\Design\Backend\File::afterLoad()), falling back to name, and anything else is JSON-encoded. json_encode() failures fall back to an [unserializable] placeholder — applied to SystemConfig::flattenValue() too, which had the same unchecked (string)json_encode(...).

Covered by new unit tests in Test/Unit/Model/Activity/ThemeConfigTest.php and SystemConfigTest.php.

Generated with Claude Code

ImanuelBertrand and others added 2 commits September 11, 2026 10:38
Saving Content > Design > Configuration posts the whole design config form,
and the imageUploader fields in it (head_shortcut_icon, header_logo_src,
email_logo, the watermark images) post a list of file descriptors, not a
scalar -- e.g. [['name' => 'logo.png', 'url' => '...', 'size' => 1234]].
normalizeValue() cast whatever it got with (string), so those fields raised
"Array to string conversion". With swissup/module-ignition installed that
warning is promoted to an ErrorException, SaveAfter aborts and
AbstractActivityObserver swallows it -- the design config is saved but no
activity is logged for the change.

Flatten arrays instead, the way the sibling Activity\SystemConfig::flattenValue()
already does for system config values, and prefer the descriptor's file name so
the logged value still compares against what core_config_data holds.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R1c3CaPXcg4sxvfv9icv69
Follow-up to f4c844a, which left three gaps:

Descriptor values were still cast unguarded, so a hand-crafted POST nesting
one level deeper (head_shortcut_icon[0][file][]=x) re-raised the very
"Array to string conversion" that commit set out to remove. Guard the cast
with is_scalar() and fall back to encoding the whole descriptor.

json_encode() returns false on malformed UTF-8, and (string)false is '', so a
real change could compare equal to an empty old value and never be logged.
Encode through a single encodeValue() that falls back to '[unserializable]',
the placeholder FieldTracker::truncateValue() already uses, and apply the same
fallback to the sibling SystemConfig::flattenValue().

Add the unit tests the branch had none of: the regression itself (re-posting
an untouched image descriptor is not a change), the name fallback, replaced
and cleared images, scalar lists, associative arrays, and both hardening cases
above. The nested-array test asserts through a scoped error handler that no
PHP warning fires, rather than relying on convertWarningsToExceptions, which
PHPUnit 10 dropped.

Rename ThemeConfig::flattenValue() to flattenPostedValue(): it shares a name
but not semantics with SystemConfig::flattenValue(), and unifying the two
would break the comparison against core_config_data.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByaeLVN4rdcm6PbfzVBUJK
@ImanuelBertrand
ImanuelBertrand requested a review from a team as a code owner September 11, 2026 10:51
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.

1 participant