-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPluginTemplatePlugin.php
More file actions
118 lines (100 loc) · 3.4 KB
/
Copy pathPluginTemplatePlugin.php
File metadata and controls
118 lines (100 loc) · 3.4 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
110
111
112
113
114
115
116
117
<?php
/**
* @file PluginTemplatePlugin.php
*
* Copyright (c) 2017-2026 Simon Fraser University
* Copyright (c) 2017-2026 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PluginTemplatePlugin
* @brief Plugin class for the PluginTemplate plugin.
*/
namespace APP\plugins\generic\pluginTemplate;
use APP\core\Application;
use APP\plugins\generic\pluginTemplate\classes\FrontEnd\ArticleDetails;
use PKP\core\APIRouter;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\VueModal;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
class PluginTemplatePlugin extends GenericPlugin
{
private PluginTemplateSettingsController $controller;
/** @copydoc GenericPlugin::register() */
public function register($category, $path, $mainContextId = null): bool
{
$success = parent::register($category, $path, $mainContextId);
if (Application::isUnderMaintenance()) {
return $success;
}
if ($success && $this->getEnabled($mainContextId)) {
// Display the publication statement on the article details page
$articleDetails = new ArticleDetails($this);
Hook::add('Templates::Article::Main', $articleDetails->addPublicationStatement(...));
// Register the settings API controller
$this->controller = new PluginTemplateSettingsController($this);
Hook::add('APIHandler::endpoints::plugin', function (string $hookName, APIRouter $apiRouter): bool {
$apiRouter->registerPluginApiControllers([
$this->controller,
]);
return Hook::CONTINUE;
});
}
return $success;
}
/**
* Provide a name for this plugin
*
* The name will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*/
public function getDisplayName(): string
{
return __('plugins.generic.pluginTemplate.displayName');
}
/**
* Provide a description for this plugin
*
* The description will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*/
public function getDescription(): string
{
return __('plugins.generic.pluginTemplate.description');
}
/**
* Add a settings action to the plugin's entry in the plugins list.
*
* @param \APP\core\Request $request
* @param array $actionArgs
*/
public function getActions($request, $actionArgs): array
{
$actions = parent::getActions($request, $actionArgs);
if (!$this->getEnabled()) {
return $actions;
}
$context = $request->getContext();
$apiUrl = $request->getDispatcher()->url(
$request,
Application::ROUTE_API,
$context->getPath(),
$this->controller->getHandlerPath()
);
$form = new PluginTemplateSettingsForm($apiUrl);
array_unshift($actions, new LinkAction(
'settings',
new VueModal(
'PkpFormModal',
[
'title' => $this->getDisplayName(),
'formConfig' => $form->getConfig(),
'getApiUrl' => $apiUrl,
]
),
__('manager.plugins.settings'),
null
));
return $actions;
}
}