Skip to content

Fix custom JSON-LD schema failing to save in Site Defaults - #642

Merged
duncanmcclean merged 1 commit into
7.xfrom
validate-json-ld-schema
Aug 7, 2026
Merged

Fix custom JSON-LD schema failing to save in Site Defaults#642
duncanmcclean merged 1 commit into
7.xfrom
validate-json-ld-schema

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request fixes an issue where saving a custom JSON-LD schema in Site Defaults blew up with TypeError: Cannot access offset of type string on string. The same field in Section Defaults saved fine.

This was happening because Code::preProcessValidatable() was added in statamic/cms v6.25.0, which unwraps ['code' => ..., 'mode' => ...] down to the bare string before validation rules run. json_ld_schema is a top-level code field in Site Defaults, so ValidJsonLd started receiving a string and choked on $value['code']. In Section Defaults the field is nested inside seo_pro_source, where SourceFieldRule builds its own validator straight from the raw value and skips preProcessValidatable() entirely, so it carried on receiving an array.

Worth noting this means the bug tracks the Statamic version rather than the SEO Pro version, which is why downgrading SEO Pro didn't help.

This PR fixes it by running the nested value through preProcessValidatable() in SourceFieldRule, so source field rules see the same shape core hands to top-level fields, and by validating the string in ValidJsonLd. As a bonus, rules like required on a source field now behave the way they do in core — previously an empty ['code' => null, 'mode' => ...] array read as non-empty.

Fixes #640
Caused by statamic/cms#14918

statamic/cms v6.25.0 added `Code::preProcessValidatable()`, which unwraps
`['code' => ..., 'mode' => ...]` to the bare string before validation runs.

`json_ld_schema` is a top-level `code` field in site defaults, so `ValidJsonLd`
now receives a string and blows up on `$value['code']`. In section defaults the
field is nested in `seo_pro_source`, where `SourceFieldRule` builds its own
validator from the raw value and skips `preProcessValidatable()` entirely, so it
kept receiving an array.

Run the nested value through `preProcessValidatable()` so source field rules see
the same shape core hands top-level fields, and validate the string in
`ValidJsonLd`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@duncanmcclean
duncanmcclean merged commit b093e63 into 7.x Aug 7, 2026
17 checks passed
@duncanmcclean
duncanmcclean deleted the validate-json-ld-schema branch August 7, 2026 11:32
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.

Cannot add custom schema object in Site Defaults

1 participant