|
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\Helpers\MenuPageHelper; |
|
8
|
|
|
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade; |
|
9
|
|
|
use GraphQLAPI\GraphQLAPI\General\RequestParams; |
|
10
|
|
|
use InvalidArgumentException; |
|
11
|
|
|
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Module Documentation menu page |
|
15
|
|
|
*/ |
|
16
|
|
|
class ModuleDocumentationMenuPage extends AbstractDocsMenuPage |
|
17
|
|
|
{ |
|
18
|
|
|
protected MenuPageHelper $menuPageHelper; |
|
19
|
|
|
|
|
20
|
|
|
function __construct(MenuPageHelper $menuPageHelper) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->menuPageHelper = $menuPageHelper; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function getMenuPageSlug(): string |
|
26
|
|
|
{ |
|
27
|
|
|
$instanceManager = InstanceManagerFacade::getInstance(); |
|
28
|
|
|
/** |
|
29
|
|
|
* @var ModulesMenuPage |
|
30
|
|
|
*/ |
|
31
|
|
|
$modulesMenuPage = $instanceManager->getInstance(ModulesMenuPage::class); |
|
32
|
|
|
return $modulesMenuPage->getMenuPageSlug(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Validate the param also |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function isCurrentScreen(): bool |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->menuPageHelper->isDocumentationScreen() && parent::isCurrentScreen(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function openInModalWindow(): bool |
|
44
|
|
|
{ |
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function useTabpanelForContent(): bool |
|
49
|
|
|
{ |
|
50
|
|
|
return true; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function getContentToPrint(): string |
|
54
|
|
|
{ |
|
55
|
|
|
// This is crazy: passing ?module=Foo\Bar\module, |
|
56
|
|
|
// and then doing $_GET['module'], returns "Foo\\Bar\\module" |
|
57
|
|
|
// So parse the URL to extract the "module" param |
|
58
|
|
|
$vars = []; |
|
59
|
|
|
parse_str($_SERVER['REQUEST_URI'], $vars); |
|
60
|
|
|
$module = urldecode($vars[RequestParams::MODULE]); |
|
61
|
|
|
$moduleRegistry = ModuleRegistryFacade::getInstance(); |
|
62
|
|
|
try { |
|
63
|
|
|
$moduleResolver = $moduleRegistry->getModuleResolver($module); |
|
64
|
|
|
} catch (InvalidArgumentException $e) { |
|
65
|
|
|
return sprintf( |
|
66
|
|
|
'<p>%s</p>', |
|
67
|
|
|
sprintf( |
|
68
|
|
|
\__('Oops, module \'%s\' does not exist', 'graphql-api'), |
|
69
|
|
|
$module |
|
70
|
|
|
) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
$hasDocumentation = $moduleResolver->hasDocumentation($module); |
|
74
|
|
|
$documentation = ''; |
|
75
|
|
|
if ($hasDocumentation) { |
|
76
|
|
|
$documentation = $moduleResolver->getDocumentation($module); |
|
77
|
|
|
} |
|
78
|
|
|
if (!$hasDocumentation || $documentation === null) { |
|
79
|
|
|
return sprintf( |
|
80
|
|
|
'<p>%s</p>', |
|
81
|
|
|
sprintf( |
|
82
|
|
|
\__('Oops, module \'%s\' has no documentation', 'graphql-api'), |
|
83
|
|
|
$moduleResolver->getName($module) |
|
84
|
|
|
) |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
return $documentation; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|