Comments (16)
@flyingcodeeurope I'm not sure I follow?
Are you using the new version of WPGraphQL for ACF v2.0?
If so you can use the register_graphql_acf_field_type()
as described above or in this guide: https://acf.wpgraphql.com/adding-support-for-3rd-party-acf-field-type/
You can put the code wherever you maintain custom code. Typically the functions.php of a child theme or a custom plugin.
from wp-graphql-acf.
Ya you'll need to add the code wherever you maintain custom code.
Typically in WordPress you would use either a child theme or a custom plugin.
from wp-graphql-acf.
@flyingcodeeurope thanks so much! I was already on the right path but was missing the use
statements. The namespace
one the other hand was not working in my functions.php
from wp-graphql-acf.
I would love for this plugin to work with wpgraph-ql. Any progress on this happening any time soon?
from wp-graphql-acf.
I included the field 'image_crop' slug in the class-config.php
public static function get_supported_fields() {
$supported_fields = [
'text',
'textarea',
'number',
'range',
'email',
'url',
'password',
'image',
'image_crop',
'file',
'wysiwyg',
'oembed',
'gallery',
'select',
'checkbox',
'radio',
'button_group',
'true_false',
'link',
'post_object',
'page_link',
'relationship',
'taxonomy',
'user',
'google_map',
'date_picker',
'date_time_picker',
'time_picker',
'color_picker',
'group',
'repeater',
'flexible_content'
];
but I don't remember if it worked. I'll install the project again here and see if it's working
from wp-graphql-acf.
Any custom extensions of ACF would need to be mapped to the WPGraphQL Schema. There's no programmatic way (that I can think of right now) to automatically have custom ACF Extensions work in the GraphQL Schema.
I'm open to suggestions if someone has an idea on how to get custom extensions to work automatically.
from wp-graphql-acf.
If anyone has this problem still and needs a quick fix you can add 'image_aspect_ratio_crop' into the $supported_fields array (mentioned above by @dinho-afsn ) in /src/class-config.php. In the same file further down in a switch statement you also need to include it there where the 'image' and 'file' case are set. This would get removed though if you update the plugin.
Thanks for the plugin @jasonbahl and if a solution was found to add this automatically that would be awesome!
from wp-graphql-acf.
Good news, I have added support for this plugin in the latest version of ACF Image Aspect Ratio Crop plugin. Iām not sure if the implementation is 100% correct but it seemed to work fine in my testing.
It would be nice to have some kind of documentation how to implement support for this plugin in a 3rd party ACF field.
from wp-graphql-acf.
šš» We're re-building this plugin over here: https://github.com/wp-graphql/wpgraphql-acf and in the new version we have a new API for mapping ACF Field Types to the GraphQL Schema.
The new version of the plugin has built-in support for ACF Extended (free and PRO), which uses the new API for mapping custom ACF Field Types to the GraphQL Schema.
It's not fully documented yet, but you can see plenty of examples of using the new register_graphql_acf_field_type()
API in this directory: https://github.com/wp-graphql/wpgraphql-acf/tree/main/src/ThirdParty/AcfExtended
Here's also a GIST showing how @CesarBenavides777 mapped the ACF Table field type to the GraphQL Schema: https://gist.github.com/CesarBenavides777/79b158db8355ddbc349fbf9b3272ae47
from wp-graphql-acf.
If anyone has this problem still and needs a quick fix you can add 'image_aspect_ratio_crop' into the $supported_fields array (mentioned above by @dinho-afsn ) in /src/class-config.php. In the same file further down in a switch statement you also need to include it there where the 'image' and 'file' case are set. This would get removed though if you update the plugin.
Thanks for the plugin @jasonbahl and if a solution was found to add this automatically that would be awesome!
Where actually should this be updated?
from wp-graphql-acf.
@jasonbahl I am looking for a way to use the ACF Image Crop in Grapql, but did not understand where to put the above code. Might be old? In this guide, https://acf.wpgraphql.com/adding-support-for-3rd-party-acf-field-type/ how do I add it?
from wp-graphql-acf.
@jasonbahl thats fine, its just that I cant figure out how to make it return the url. Its just giving me,
"teaserPhotoWide": "312312". Seems to be the ID.
from wp-graphql-acf.
@flyingcodeeurope is the value an ID of an image?
If so you could get inspiration from how the Image field does things: https://github.com/wp-graphql/wpgraphql-acf/blob/develop/src/FieldType/Image.php
I'm not familiar with the Image Crop acf field type enough to know how to best support it. I think my best advice would be to draw inspiration from other fields we are supporting and implement in a similar way.
If you have a clear idea of how you would like it to show in the Schema but aren't quite sure how to get it there let me know
from wp-graphql-acf.
@jasonbahl I know I want it to output it as url only. Not 100% sure how to achieve that... I played around with the code and actually managed what I wanted. Thank you for your great help pointing me in the right direction.
from wp-graphql-acf.
@jasonbahl I know I want it to output it as url only. Not 100% sure how to achieve that... I played around with the code and actually managed what I wanted. Thank you for your great help pointing me in the right direction.
Can you show how you did it? I'm struggling, trying to get the entire image object though...
from wp-graphql-acf.
@robkrause this is my full code to add it to graphql:
`<?php
namespace WPGraphQL\Acf\FieldType;
use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\Acf\AcfGraphQLFieldType;
use WPGraphQL\Acf\FieldConfig;
use WPGraphQL\AppContext;
use WPGraphQL\Data\Connection\PostObjectConnectionResolver;
add_action( 'wpgraphql/acf/registry_init', function() {
register_graphql_acf_field_type(
'image_aspect_ratio_crop',
[
'exclude_admin_fields' => [ 'graphql_non_null' ],
'graphql_type' => static function ( FieldConfig $field_config, AcfGraphQLFieldType $acf_field_type ) {
if ( empty( $field_config->get_graphql_field_group_type_name() ) || empty( $field_config->get_graphql_field_name() ) ) {
return null;
}
$type_name = $field_config->get_graphql_field_group_type_name();
$to_type = 'MediaItem';
$field_config->register_graphql_connections(
[
'description' => $field_config->get_field_description(),
'acf_field' => $field_config->get_acf_field(),
'acf_field_group' => $field_config->get_acf_field_group(),
'fromType' => $type_name,
'toType' => $to_type,
'fromFieldName' => $field_config->get_graphql_field_name(),
'oneToOne' => true,
'resolve' => static function ( $root, $args, AppContext $context, ResolveInfo $info ) use ( $field_config ) {
$value = $field_config->resolve_field( $root, $args, $context, $info );
if ( is_object( $value ) && isset( $value->ID ) ) {
$value = $value->ID;
}
if ( is_array( $value ) && isset( $value['ID'] ) ) {
$value = $value['ID'];
}
if ( empty( $value ) || ! absint( $value ) ) {
return null;
}
$resolver = new PostObjectConnectionResolver( $root, $args, $context, $info, 'attachment' );
return $resolver
->one_to_one()
->set_query_arg( 'p', absint( $value ) )
->get_connection();
},
'allowFieldUnderscores' => true,
]
);
return 'connection';
},
]
);
});
?>`
from wp-graphql-acf.
Related Issues (20)
- High CPU usage for get_location_rules() inside `add_acf_fields_to_graphql_types` HOT 2
- Querying for a custom post type by one of it's ACF field values HOT 2
- Fetching Data from User Relationship Field Returns Null HOT 3
- Get all the ACF fields object HOT 1
- Empty response when content includes non-allowed HTML tag HOT 2
- Get formatted ACF field data HOT 2
- PHP Deprecated: Optional parameter $and_params declared before required parameter $param HOT 2
- Getting GraphQL-Error if PostObject is null HOT 1
- Both WPGraphQL (v0.4.0+) and Advanced Custom Fields (v5.7+) must be active for "wp-graphql-acf" to work HOT 1
- ACF fields is not showing in graphiql IDE HOT 4
- GraphQL not working when defining sub options page HOT 3
- Using a date sub_field nested in a repeater as a filter / sorting method ? HOT 1
- ACF Taxonomy & Custom Field filtering HOT 2
- Where condition for ACF doesn't work....??? HOT 2
- Query on Taxonomy gives error on graphql response HOT 3
- Post object as draft return null value which causes internal server error HOT 2
- Troubleshooting taxonomy field in flexible content HOT 1
- Deprecated function "WPGraphQL\Data\DataSource::resolve_post_object" HOT 1
- Option page ACF fields are null when using Graphiql in Gatsby HOT 2
- Cannot mutate relationship ACF field on userUpdate HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-graphql-acf.