Describe the issue or problem
I am trying to add a new field to the context/journal in a plugin I am developing. It is a single text field, which needs to be saved in journal_settings.
To interact with the plugin, I also created a custom API endpoint. This endpoint extends APIHandler/PKPHandler. In here the hook “Schema::get::context” is not triggered. However, the hook “Schema::get::publication” and others are triggered.
Am I missing something obvious?
Can I extend the schema some other way in my plugin?
Steps I took leading up to the issue
- Plugin::isSitePlugin true / false
- passed my plugin object as a parameter to the APIHandler
- created a new instance of my plugin class
What application are you using?
OJS 3.3.0-16
OJS 3.4.0-4
Additional information
This is the plugin (branch) I am working on: GitHub - GaziYucel/citationManager at dev-3_4_0
Below is a short version of the code I use.
OJS 3.4.0-4
public function register(...)
{
....
if ($success && $this->getEnabled()) {
Hook::add('Schema::get::context', [$this, 'addToSchemaContext']);
Hook::add('Schema::get::publication', [$this, 'addToSchemaPublication']);
Hook::add('Dispatcher::dispatch', [$this, 'registerApi']);
...
}
}
public function addToSchemaContext($hookName, $args)
{
$schema->properties->CitationManager_JournalMetadata = (object)[
"type" => "string",
"multilingual" => false,
"apiSummary" => true,
"validation" => ["nullable"]
];
}
public function addToSchemaPublication($hookName, $args)
{
$schema->properties->CitationManager_PublicationMetadata = (object)[
"type" => "string",
"multilingual" => false,
"apiSummary" => true,
"validation" => ["nullable"]
];
}
public function registerApi($hookName, $args)
{
/* @var Request $request */
$request = $args[0];
$router = $request->getRouter();
if ($router instanceof APIRouter
&& str_contains($request->getRequestPath(), 'api/v1/myPluginEndpoint')
) {
$handler = new MyPluginAPIHandler($this);
$router->setHandler($handler);
$handler->getApp()->run();
exit;
return false;
}