Skip to content

Commit

Permalink
Fix: Properly extract innerHTML from source attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
theodesp committed Jan 2, 2024
1 parent 550aaa1 commit 72b3210
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions includes/Blocks/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function register_block_attributes_as_fields(): void {
* @param object $attribute The block attribute config
* @param string $prefix Current prefix string to use for the get_query_type
*/
private function get_attribute_type( $name, $attribute, $prefix ) {
private function get_attribute_type( $name, $attribute, $prefix ): mixed {
$type = null;

if ( isset( $attribute['type'] ) ) {
Expand Down Expand Up @@ -185,6 +185,8 @@ private function get_attribute_type( $name, $attribute, $prefix ) {
*
* @param ?array $block_attributes The block attributes.
* @param string $prefix The current prefix string to use for the get_query_type
*
* @return array
*/
private function get_block_attribute_fields( ?array $block_attributes, $prefix = null ): array {
$fields = [];
Expand All @@ -193,7 +195,7 @@ private function get_block_attribute_fields( ?array $block_attributes, $prefix =
if ( null === $block_attributes ) {
return $fields;
}

foreach ( $block_attributes as $attribute_name => $attribute_config ) {
$graphql_type = self::get_attribute_type( $attribute_name, $attribute_config, $prefix );

Expand Down Expand Up @@ -230,7 +232,7 @@ private function get_block_attribute_fields( ?array $block_attributes, $prefix =
* @param array $query The block query config
* @param string $prefix The current prefix string to use for registering the new query attribute type
*/
private function get_query_type( $name, $query, $prefix ) {
private function get_query_type( $name, $query, $prefix ): string {
$type = $prefix . ucfirst( $name );

$fields = $this->create_attributes_fields( $query, $type );
Expand All @@ -256,8 +258,10 @@ private function get_query_type( $name, $query, $prefix ) {
*
* @param array $attributes The query attributes config
* @param string $prefix The current prefix string to use for registering the new query attribute type
*
* @return array
*/
private function create_attributes_fields( $attributes, $prefix ) {
private function create_attributes_fields( $attributes, $prefix ): array {
$fields = [];
foreach ( $attributes as $name => $attribute ) {
$type = $this->get_attribute_type( $name, $attribute, $prefix );
Expand All @@ -284,7 +288,7 @@ private function create_attributes_fields( $attributes, $prefix ) {
* @param array|string $value The value
* @param string $type The type of the value
*/
private function normalize_attribute_value( $value, $type ) {
private function normalize_attribute_value( $value, $type ): mixed {
switch ( $type ) {
case 'string':
return (string) $value;
Expand Down Expand Up @@ -358,8 +362,10 @@ private function resolve( $block ) {
* @param array $attributes The block current attributes value
* @param string $html The block rendered html
* @param array $config The block current attribute configuration
*
* @return array
*/
private function resolve_block_attributes_recursive( $attributes, $html, $config ) {
private function resolve_block_attributes_recursive( $attributes, $html, $config ): array {
$result = [];
foreach ( $config as $key => $value ) {
// Get default value.
Expand Down Expand Up @@ -428,14 +434,14 @@ private function resolve_block_attributes_recursive( $attributes, $html, $config
* @param string $html The html value
* @param string $source The source type
*/
private function parse_single_source( $html, $source ) {
private function parse_single_source( $html, $source ): string|null {
$value = null;
if ( empty( $html ) ) {
return $value;
}
switch ( $source ) {
case 'html':
$value = $html;
$value = DOMHelpers::findNodes( $html )->innerHTML();
break;
}
return $value;
Expand Down
2 changes: 1 addition & 1 deletion includes/Utilities/DomHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function parseText( $html, $selector ) {
* @param string $html The HTML string to parse.
* @param string|null $selector The selector to use.
*
* @return \DOMElement[]
* @return \DOMElement[]|\WPGraphQL\ContentBlocks\Utilities\DOMElement
*/
public static function findNodes( $html, $selector = null ) {
$value = null;
Expand Down

0 comments on commit 72b3210

Please sign in to comment.