Files
wp-graphql-woocommerce/includes/connection/class-posts.php
T

50 lines
1.1 KiB
PHP
Raw Normal View History

2019-03-31 23:16:11 -04:00
<?php
/**
* Connection type - Posts
*
* Registers connections to Posts
*
2019-10-25 19:13:36 -04:00
* @package WPGraphQL\WooCommerce\Connection
2019-03-31 23:16:11 -04:00
*/
2019-10-25 19:13:36 -04:00
namespace WPGraphQL\WooCommerce\Connection;
2019-03-31 23:16:11 -04:00
use WPGraphQL\Connection\PostObjects;
/**
* Class - Posts
*/
class Posts extends PostObjects {
/**
* Registers the various connections from other WooCommerce Types to other WordPress post-types
*/
public static function register_connections() {
2019-10-24 22:11:04 -04:00
register_graphql_connection(
self::get_connection_config(
get_post_type_object( 'attachment' ),
array(
'fromType' => 'Product',
'toType' => 'MediaItem',
'fromFieldName' => 'galleryImages',
)
)
);
2019-03-31 23:16:11 -04:00
/**
2019-10-17 21:39:38 -04:00
* From product types to MediaItem
2019-03-31 23:16:11 -04:00
*/
2019-10-17 21:39:38 -04:00
$product_types = array_values( \WP_GraphQL_WooCommerce::get_enabled_product_types() );
foreach ( $product_types as $product_type ) {
register_graphql_connection(
self::get_connection_config(
get_post_type_object( 'attachment' ),
array(
'fromType' => $product_type,
'toType' => 'MediaItem',
'fromFieldName' => 'galleryImages',
)
2019-03-31 23:16:11 -04:00
)
2019-10-17 21:39:38 -04:00
);
}
2019-03-31 23:16:11 -04:00
}
}