|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\MenuPages; |
|
6
|
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\MenuPages\AbstractMenuPage; |
|
8
|
|
|
use GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\MenuPages\EnqueueReactMenuPageTrait; |
|
9
|
|
|
use GraphQLAPI\GraphQLAPI\General\EndpointHelpers; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Voyager page |
|
13
|
|
|
*/ |
|
14
|
|
|
class GraphQLVoyagerMenuPage extends AbstractMenuPage |
|
15
|
|
|
{ |
|
16
|
|
|
use EnqueueReactMenuPageTrait; |
|
17
|
|
|
use GraphQLAPIMenuPageTrait; |
|
18
|
|
|
|
|
19
|
|
|
public function print(): void |
|
20
|
|
|
{ |
|
21
|
|
|
?> |
|
22
|
|
|
<div id="voyager" class="voyager-client"><?php echo __('Loading...', 'graphql-api') ?></div> |
|
23
|
|
|
<?php |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getMenuPageSlug(): string |
|
27
|
|
|
{ |
|
28
|
|
|
return 'voyager'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Enqueue the required assets and initialize the localized scripts |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function enqueueAssets(): void |
|
37
|
|
|
{ |
|
38
|
|
|
parent::enqueueAssets(); |
|
39
|
|
|
|
|
40
|
|
|
// CSS |
|
41
|
|
|
\wp_enqueue_style( |
|
42
|
|
|
'graphql-api-voyager-client', |
|
43
|
|
|
\GRAPHQL_API_URL . 'assets/css/voyager-client.css', |
|
44
|
|
|
array(), |
|
45
|
|
|
\GRAPHQL_API_VERSION |
|
46
|
|
|
); |
|
47
|
|
|
\wp_enqueue_style( |
|
48
|
|
|
'graphql-api-voyager', |
|
49
|
|
|
\GRAPHQL_API_URL . 'assets/css/vendors/voyager.css', |
|
50
|
|
|
array(), |
|
51
|
|
|
\GRAPHQL_API_VERSION |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
// JS: execute them all in the footer |
|
55
|
|
|
$this->enqueueReactAssets(true); |
|
56
|
|
|
\wp_enqueue_script( |
|
57
|
|
|
'graphql-api-voyager', |
|
58
|
|
|
\GRAPHQL_API_URL . 'assets/js/vendors/voyager.min.js', |
|
59
|
|
|
array('graphql-api-react-dom'), |
|
60
|
|
|
\GRAPHQL_API_VERSION, |
|
61
|
|
|
true |
|
62
|
|
|
); |
|
63
|
|
|
\wp_enqueue_script( |
|
64
|
|
|
'graphql-api-voyager-client', |
|
65
|
|
|
\GRAPHQL_API_URL . 'assets/js/voyager-client.js', |
|
66
|
|
|
array('graphql-api-voyager'), |
|
67
|
|
|
\GRAPHQL_API_VERSION, |
|
68
|
|
|
true |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
// Load data into the script |
|
72
|
|
|
\wp_localize_script( |
|
73
|
|
|
'graphql-api-voyager-client', |
|
74
|
|
|
'graphQLByPoPGraphiQLSettings', |
|
75
|
|
|
array( |
|
76
|
|
|
'nonce' => \wp_create_nonce('wp_rest'), |
|
77
|
|
|
'endpoint' => EndpointHelpers::getAdminGraphQLEndpoint(), |
|
78
|
|
|
) |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|