Fix custom JSON-LD schema failing to save in Site Defaults - #642
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_schemais a top-levelcodefield in Site Defaults, soValidJsonLdstarted receiving a string and choked on$value['code']. In Section Defaults the field is nested insideseo_pro_source, whereSourceFieldRulebuilds its own validator straight from the raw value and skipspreProcessValidatable()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()inSourceFieldRule, so source field rules see the same shape core hands to top-level fields, and by validating the string inValidJsonLd. As a bonus, rules likerequiredon 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