-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathPolylangTypes.php
More file actions
109 lines (101 loc) · 3.34 KB
/
Copy pathPolylangTypes.php
File metadata and controls
109 lines (101 loc) · 3.34 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace WPGraphQL\Extensions\Polylang;
class PolylangTypes
{
function init()
{
add_action(
'graphql_register_types',
[$this, '__action_graphql_register_types'],
9,
0
);
}
function __action_graphql_register_types()
{
$language_codes = [];
foreach (pll_languages_list() as $lang) {
$language_codes[strtoupper($lang)] = $lang;
}
if (empty($language_codes)) {
$locale = get_locale();
$language_codes[strtoupper($locale)] = [
'value' => $locale,
'description' => __(
'The default locale of the site',
'wp-graphql-polylang'
),
];
}
register_graphql_enum_type('LanguageCodeEnum', [
'description' => __(
'Enum of all available language codes',
'wp-graphql-polylang'
),
'values' => $language_codes,
]);
register_graphql_enum_type('LanguageCodeFilterEnum', [
'description' => __(
'Filter item by specific language, default language or list all languages',
'wp-graphql-polylang'
),
'values' => array_merge($language_codes, [
'DEFAULT' => 'default',
'ALL' => 'all',
]),
]);
register_graphql_object_type('Language', [
'description' => __('Language (Polylang)', 'wp-graphql-polylang'),
'fields' => [
'id' => [
'type' => [
'non_null' => 'ID',
],
'description' => __(
'Language ID (Polylang)',
'wp-graphql-polylang'
),
],
'name' => [
'type' => 'String',
'description' => __(
'Human readable language name (Polylang)',
'wp-graphql-polylang'
),
],
'code' => [
'type' => 'LanguageCodeEnum',
'description' => __(
'Language code (Polylang)',
'wp-graphql-polylang'
),
],
'locale' => [
'type' => 'String',
'description' => __(
'Language locale (Polylang)',
'wp-graphql-polylang'
),
],
'slug' => [
'type' => 'String',
'description' => __(
'Language term slug. Prefer the "code" field if possible (Polylang)',
'wp-graphql-polylang'
),
],
'active' => [
'type' => 'Boolean',
'description' => __('Is language active.'),
],
'homeUrl' => [
'type' => 'String',
'description' => __(
'Language term front page URL',
'wp-graphql-polylang'
),
],
],
]);
}
}