Describe the issue or problem
I am trying add some custom fields into site-wide schema by hook Schema::get::site however, this field is not added to site-wide schema.
My Plugin class
<?php
/**
* @file plugins/generic/customSchemas/CustomSchemasPlugin.inc.php
*
* @class CustomSchemasPlugin
* @ingroup plugins_generic_customSchemas
*
* @brief Custom Schemas plugin class
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class CustomSchemasPlugin extends GenericPlugin
{
public function isSitePlugin()
{
return true;
}
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled($mainContextId)) {
HookRegistry::register('Schema::get::site', array($this, 'addToSiteSchema'));
HookRegistry::register('Form::config::before', array($this, 'addToForm'));
}
return $success;
}
function getDisplayName()
{
return 'Custom Schemas';
}
function getDescription()
{
return 'Custom Schemas';
}
public function addToSiteSchema($hookName, $args)
{
$schema = $args[0];
$schema->properties->pageHeaderIconImage = (object) [
'type' => 'object',
'apiSummary' => true,
'multilingual' => true,
'validation' => ['nullable'],
'properties' => [
"temporaryFileId" => [
"type" => "integer",
"writeOnly" => true
],
"name" => [
"type" => "string"
],
"uploadName" => [
"type" => "string"
],
"width" => [
"type" => "integer"
],
"height" => [
"type" => "integer"
],
"dateUploaded" => [
"type" => "string"
],
"altText" => [
"type" => "string"
]
]
];
$schema->properties->homepageImage = (object) [
'type' => 'object',
'apiSummary' => true,
'multilingual' => true,
'validation' => ['nullable'],
'properties' => [
"temporaryFileId" => [
"type" => "integer",
"writeOnly" => true
],
"name" => [
"type" => "string"
],
"uploadName" => [
"type" => "string"
],
"width" => [
"type" => "integer"
],
"height" => [
"type" => "integer"
],
"dateUploaded" => [
"type" => "string"
],
"altText" => [
"type" => "string"
]
]
];
return false;
}
public function addtoForm($hookName, $form) {
static $isAddedAdminFormSiteAppearance = false;
// Don't do anything at the site-wide level
$request = Application::get()->getRequest();
$context = $request->getContext();
if (!$context) {
$site = $request->getSite();
$dispatcher = $request->getDispatcher();
$temporaryFileApiUrl = $dispatcher->url($request, ROUTE_API, CONTEXT_ID_ALL, 'temporaryFiles');
import('classes.file.PublicFileManager');
$publicFileManager = new PublicFileManager();
$baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath();
if (defined('FORM_SITE_APPEARANCE') && $form->id === FORM_SITE_APPEARANCE) {
if ($isAddedAdminFormSiteAppearance) {
return false; // Nếu đã chạy rồi thì thoát ngay
}
$form->addField(new \PKP\components\forms\FieldUploadImage('pageHeaderIconImage', [
'label' => __('manager.setup.pageHeaderIconImage'),
'value' => $site->getData('pageHeaderIconImage'),
'isMultilingual' => true,
'baseUrl' => $baseUrl,
'options' => [
'url' => $temporaryFileApiUrl,
],
]))
->addField(new \PKP\components\forms\FieldUploadImage('homepageImage', [
'label' => __('manager.setup.homepageImage'),
'tooltip' => __('manager.setup.homepageImage.description'),
'value' => $site->getData('homepageImage'),
'isMultilingual' => true,
'baseUrl' => $baseUrl,
'options' => [
'url' => $temporaryFileApiUrl,
],
]));
$isAddedAdminFormSiteAppearance = true; // Đánh dấu đã xử lý xong
return false;
}
return false;
}
return false;
}
}
What application are you using?
For example, OJS 3.3.0-x
Anyone who has encountered this error and can help me. Sincerely thank.
