Skip to content

Guard Gutenberg block data handling against array-valued ACF fields - #2063

Draft
sebastianthulin with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-str-contains-type-error
Draft

Guard Gutenberg block data handling against array-valued ACF fields#2063
sebastianthulin with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-str-contains-type-error

Conversation

Copilot AI commented May 28, 2026

Copy link
Copy Markdown
Contributor

Municipio\Admin\Gutenberg\Blocks\BlockManager assumed all block data values were strings and called str_contains() unconditionally. Container/block data coming from ACF can include arrays, which caused runtime type errors during render and validation.

  • Runtime guard for mixed block data

    • Add string checks before resolving field references in buildData()
    • Preserve non-string values as-is so array-backed block fields continue through the render path unchanged
  • Validation hardening

    • Apply the same string guard in validateFields()
    • Only treat actual ACF field keys as resolvable/validatable references
    • Avoid descendant checks on non-string parent values
  • Regression coverage

    • Add focused tests for:
      • array-valued block data passed into buildData()
      • arrays containing field-like strings that should not be resolved implicitly
      • required-field validation still working when mixed with array-valued data
if (is_string($value) && str_contains($value, 'field_')) {
    $newData[$key] = get_field($value);
}

Copilot AI changed the title [WIP] Fix str_contains argument type error in BlockManager Guard Gutenberg block data handling against array-valued ACF fields May 28, 2026
Copilot AI requested a review from sebastianthulin May 28, 2026 13:41
@sonarqubecloud

Copy link
Copy Markdown

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.

str_contains(): Argument #1 ($haystack) must be of type string, array given

2 participants