-
Notifications
You must be signed in to change notification settings - Fork 442
/
ContentTypeConnectionResolver.php
83 lines (71 loc) · 1.44 KB
/
ContentTypeConnectionResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace WPGraphQL\Data\Connection;
/**
* Class ContentTypeConnectionResolver
*
* @package WPGraphQL\Data\Connection
*/
class ContentTypeConnectionResolver extends AbstractConnectionResolver {
/**
* {@inheritDoc}
*
* @var string[]
*/
protected $query;
/**
* {@inheritDoc}
*/
public function get_ids_from_query() {
$ids = [];
$queried = $this->query;
if ( empty( $queried ) ) {
return $ids;
}
foreach ( $queried as $item ) {
$ids[] = $item;
}
return $ids;
}
/**
* {@inheritDoc}
*/
public function get_query_args() {
// If any args are added to filter/sort the connection
return [];
}
/**
* {@inheritDoc}
*
* @return string[]
*/
public function get_query() {
if ( isset( $this->query_args['contentTypeNames'] ) && is_array( $this->query_args['contentTypeNames'] ) ) {
return $this->query_args['contentTypeNames'];
}
if ( isset( $this->query_args['name'] ) ) {
return [ $this->query_args['name'] ];
}
$query_args = $this->query_args;
return \WPGraphQL::get_allowed_post_types( 'names', $query_args );
}
/**
* {@inheritDoc}
*/
protected function loader_name(): string {
return 'post_type';
}
/**
* {@inheritDoc}
*
* @param string $offset The offset (post type name) to check.
*/
public function is_valid_offset( $offset ) {
return (bool) get_post_type_object( $offset );
}
/**
* {@inheritDoc}
*/
public function should_execute() {
return true;
}
}