PluginProbe
WPGraphQL / trunk
WPGraphQL vtrunk
2.22.3 2.22.2 2.22.1 2.22.0 2.21.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.15.0 2.14.1 2.14.0 2.13.0 2.2.0 2.3.0 2.3.3 2.3.6 2.3.8 2.5.0 2.5.1 2.5.2 2.5.3 All 177 releases
wp-graphql / deprecated / TermObjectUnion.php

TermObjectUnion.php in WPGraphQL trunk, at deprecated/TermObjectUnion.php

70 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPGraphQL\Type\Union;
3
4 use WPGraphQL\Registry\TypeRegistry;
5
6 /**
7 * @todo Remove in 3.0.0
8 * @deprecated 1.14.1
9 * @codeCoverageIgnore
10 */
11 class TermObjectUnion {
12
13 /**
14 * Registers the Type
15 *
16 * @param ?\WPGraphQL\Registry\TypeRegistry $type_registry
17 *
18 * @throws \Exception
19 */
20 public static function register_type( ?TypeRegistry $type_registry = null ): void {
21 register_graphql_union_type(
22 'TermObjectUnion',
23 [
24 'kind' => 'union',
25 'typeNames' => self::get_possible_types(),
26 'description' => static function () {
27 return __( 'Union between the Category, Tag and PostFormatPost types', 'wp-graphql' );
28 },
29 'resolveType' => static function ( $value ) {
30 _doing_it_wrong(
31 self::class,
32 esc_attr__( 'The TermObjectUnion GraphQL type is deprecated and will be removed in the next version of WordPress. Use the TermNode interface instead.', 'wp-graphql' ),
33 '1.14.1'
34 );
35
36 $type = null;
37 if ( isset( $value->taxonomyName ) ) {
38 $tax_object = get_taxonomy( $value->taxonomyName );
39 if ( isset( $tax_object->graphql_single_name ) ) {
40 $type = \WPGraphQL::get_type_registry()->get_type( $tax_object->graphql_single_name );
41 }
42 }
43
44 return ! empty( $type ) ? $type : null;
45 },
46 ]
47 );
48 }
49
50 /**
51 * Returns a list of possible types for the union
52 *
53 * @return array<string,string>
54 */
55 public static function get_possible_types() {
56 $possible_types = [];
57 $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies( 'objects', [ 'graphql_kind' => 'object' ] );
58
59 foreach ( $allowed_taxonomies as $tax_object ) {
60 if ( empty( $possible_types[ $tax_object->name ] ) ) {
61 if ( isset( $tax_object->graphql_single_name ) ) {
62 $possible_types[ $tax_object->name ] = $tax_object->graphql_single_name;
63 }
64 }
65 }
66
67 return $possible_types;
68 }
69 }
70