Skip to content

Commit

Permalink
Merge pull request #111 from wp-graphql/fix/#106-oembed-field-support
Browse files Browse the repository at this point in the history
fix: oembed field type returns embed instead of URL entered to the field
  • Loading branch information
jasonbahl authored Nov 6, 2023
2 parents 31c56c6 + 2fcef1a commit 62fcc6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/FieldConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public function should_format_field_value( string $field_type ): bool {
'select',
'wysiwyg',
'repeater',
'oembed',
];

return in_array( $field_type, $types_to_format, true );
Expand Down Expand Up @@ -440,7 +441,7 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
*
* @param mixed $value
* @param array $field_config The ACF Field Config for the field being resolved
* @param mixed $root The Root node or obect of the field being resolved
* @param mixed $root The Root node or object of the field being resolved
* @param mixed $node_id The ID of the node being resolved
*/
return apply_filters( 'wpgraphql/acf/field_value', $prepared_value, $field_config, $root, $node_id );
Expand Down
9 changes: 9 additions & 0 deletions tests/wpunit/FieldTypes/OembedFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public function tearDown(): void {
parent::tearDown();
}

public function get_clone_value_to_save(): string {
return 'https://twitter.com/wpgraphql/status/1115652591705190400';
}

public function get_field_type(): string {
return 'oembed';
}
Expand All @@ -33,4 +37,9 @@ public function get_acf_clone_fragment(): string {
';
}

public function get_expected_clone_value() {
return wp_oembed_get( $this->get_clone_value_to_save(), [ 'width' => 550 ] );

}

}
5 changes: 3 additions & 2 deletions tests/wpunit/PostObjectFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,9 @@ public function testQueryOembedField() {
'name' => 'oembed_field',
]);

$expected = 'https://twitter.com/wpgraphql/status/1115652591705190400';
update_field( 'oembed_field', $expected, $this->post_id );
$input = 'https://twitter.com/wpgraphql/status/1115652591705190400';
update_field( 'oembed_field', $input, $this->post_id );
$expected = wp_oembed_get( $input, [ 'width' => 550 ] );

$query = '
query GET_POST_WITH_ACF_FIELD( $postId: Int! ) {
Expand Down

0 comments on commit 62fcc6a

Please sign in to comment.