diff --git a/.changeset/good-poems-battle.md b/.changeset/good-poems-battle.md new file mode 100644 index 0000000..7e2f3b4 --- /dev/null +++ b/.changeset/good-poems-battle.md @@ -0,0 +1,5 @@ +--- +"@wpengine/wp-graphql-content-blocks": patch +--- + +fix: handle arrays before casting when using `Block::normalize_attribute_value()` diff --git a/includes/Blocks/Block.php b/includes/Blocks/Block.php index 1e88006..f014106 100644 --- a/includes/Blocks/Block.php +++ b/includes/Blocks/Block.php @@ -292,10 +292,18 @@ private function create_attributes_fields( $attributes, $prefix ): array { * @param array|string $value The value * @param string $type The type of the value * - * @return mixed + * @return array|string|int|float|bool */ private function normalize_attribute_value( $value, $type ) { + // @todo use the `source` to normalize array/object values. + if ( is_array( $value ) ) { + return $value; + } + switch ( $type ) { + case 'array': + // If we're here, we want an array type, even though the value is not an array. + return isset( $value ) ? [ $value ] : []; case 'string': return (string) $value; case 'number': diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ea2b7dc..23c2223 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,11 +5,6 @@ parameters: count: 1 path: includes/Blocks/Block.php - - - message: "#^Cannot cast array\\|string to string\\.$#" - count: 1 - path: includes/Blocks/Block.php - - message: "#^Constant WPGRAPHQL_CONTENT_BLOCKS_PLUGIN_DIR not found\\.$#" count: 4