Skip to content

Commit

Permalink
fix: handle arrays before casting when normalizing attribute values (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine committed Apr 8, 2024
1 parent d00ee4a commit e348494
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-poems-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": patch
---

fix: handle arrays before casting when using `Block::normalize_attribute_value()`
10 changes: 9 additions & 1 deletion includes/Blocks/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e348494

Please sign in to comment.