I would like to kindly ask for assistance with a plugin I am developing for OJS 3.4. The goal of the plugin is to add a new editable field for the UDC code in the Identifiers section in the Publication tab, which would be filled in by the editor. The field should be stored in a separate table in the database.
Below, I have included the code for the UDCPlugin.php file. I have also created the necessary version.xml, index.php and the corresponding localization files. The plugin appears in the plugin gallery and activates correctly. However, the Identifiers group in the Publication tab does not appear, and as a result, I am unable to test the plugin further. In addition, I will eventually need to display the UDC code in the template of my custom theme.
I would be very grateful for any guidance or suggestions on how to resolve this issue and successfully implement the UDC field.
Thanks in advance for support.
udcPlugin.php
<?php
namespace APP\plugins\generic\udc;
use APP\core\Application;
use PKP\components\forms\FieldText;
use PKP\components\forms\FormComponent;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use stdClass;
class UDCPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled()) {
Hook::add('Schema::get::publication', [$this, 'addToSchema']);
Hook::add('Form::config::before', [$this, 'addToForm']);
Hook::add('Templates::Article::Details', [$this, 'displayUDCInTemplate']);
}
return $success;
}
public function addToSchema(string $hookName, array $args)
{
$schema = $args[0]; /** @var stdClass */
$schema->properties->udc = (object) [
'type' => 'string',
'validation' => ['nullable'],
'apiSummary' => true,
];
return false;
}
public function addToForm(string $hookName, FormComponent $form): bool
{
if (!defined('FORM_PUBLICATION') || $form->id !== 'publicationIdentifiers') {
return false;
}
$publication = $form->getData('publication');
$form->addField(new FieldText('udc', [
'label' => __('plugins.generic.udc.formLabel'),
'groupId' => 'identifiers',
'value' => $publication->getData('udc'),
]));
return false;
}
public function displayUDCInTemplate(string $hookName, array $args): bool
{
$smarty = $args[0];
$output = &$args[2];
$publication = $smarty->getTemplateVars('publication');
if (!$publication) {
return false;
}
$udcCode = $publication->getData('udc');
if ($udcCode) {
$output .= htmlspecialchars($udcCode);
}
return false;
}
public function getDisplayName(): string
{
return __('plugins.generic.udc.displayName');
}
public function getDescription(): string
{
return __('plugins.generic.udc.description');
}
}