Hello Again,
The plugin was successfully installed and enabled, but the discipline metadata wasn’t showing on the article page. This was likely due to OJS 3.4’s changes in routing and hook handling. I’ve adjusted the plugin to use ArticleHandler::view
, assign the discipline data using TemplateManager::assign()
, and ensure it’s rendered in the article template.
My purpose is to view the Discipline in the article page.
Below is the code that needs to be checked — until now, it’s still not viewing on the article page:
Plugin Structure
ShowDisciplinePlugin/
├── ShowDisciplinePluginPlugin.php
├── plugin.json
├── version.xml
├── locale/
│ └── en_US/
│ └── locale.xml
└── templates/
└── frontend/
└── objects/
└── article_details.tpl
ShowDisciplinePluginPlugin.php
<?php
namespace APP\plugins\generic\ShowDisciplinePlugin;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use APP\submission\Submission;
class ShowDisciplinePluginPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null): bool
{
if (!parent::register($category, $path, $mainContextId)) return false;
$this->addLocaleData();
Hook::add('ArticleHandler::view', [$this, 'addDisciplineToTemplate']);
return true;
}
public function addDisciplineToTemplate($hookName, $args)
{
$request = $args[0];
$article = $args[1];
if (!$article instanceof Submission) return false;
$templateMgr = \TemplateManager::getManager($request);
$disciplines = $this->getDisciplines($article);
if (!empty($disciplines)) {
$templateMgr->assign('disciplineText', implode(', ', $disciplines));
}
return false;
}
private function getDisciplines(Submission $article): array
{
$publication = $article->getCurrentPublication();
$publicationId = $publication->getId();
$contextId = $article->getData('contextId');
$locale = \App::getLocale();
$vocabDao = \DAORegistry::getDAO('ControlledVocabDAO');
$vocab = $vocabDao->getBySymbolic('submissionDiscipline', ASSOC_TYPE_PUBLICATION, $publicationId, $contextId);
if (!$vocab) return [];
$entryDao = \DAORegistry::getDAO('ControlledVocabEntryDAO');
$entries = $entryDao->getByControlledVocabId($vocab->getId())->toArray();
$result = [];
foreach ($entries as $entry) {
$label = $entry->getLocalizedSetting('submissionDiscipline', $locale);
if ($label) {
$result[] = $label;
}
}
return $result;
}
public function getDisplayName(): string
{
return __('plugins.generic.ShowDisciplinePlugin.name');
}
public function getDescription(): string
{
return __('plugins.generic.ShowDisciplinePlugin.description');
}
}
plugin.json
{
"name": "ShowDisciplinePlugin",
"category": "generic",
"version": "1.0.0",
"mainClass": "APP\\\\plugins\\\\generic\\\\ShowDisciplinePlugin\\\\ShowDisciplinePluginPlugin",
"enabled": true
}
version.xml
<?xml version="1.0" encoding="UTF-8"?>
<version>
<application>ShowDisciplinePlugin</application>
<type>plugins.generic</type>
<release>1.0.0</release>
<date>2025-06-20</date>
<lazyLoad>true</lazyLoad>
</version>
locale/en_US/locale.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE locale SYSTEM "../../../../lib/pkp/dtd/locale.dtd">
<locale name="en_US" full_name="English (US)">
<message key="plugins.generic.ShowDisciplinePlugin.name">Show Discipline Plugin</message>
<message key="plugins.generic.ShowDisciplinePlugin.description">Displays the discipline metadata before the abstract on the article page.</message>
<message key="submission.discipline">Discipline</message>
</locale>
templates/frontend/objects/article_details.tpl
{** Custom Article Template for ShowDisciplinePlugin **}
{if $disciplineText}
<section class="item discipline">
<h2 class="label">{translate key="submission.discipline"}</h2>
<span class="value">{$disciplineText|escape}</span>
</section>
{/if}
<section class="item abstract">
<h2 class="label">{translate key="article.abstract"}</h2>
<div class="value">
{$article->getLocalizedData('abstract')|strip_unsafe_html|nl2br}
</div>
</section>
Recap
Plugin installs and enables.
Discipline metadata still not showing.
Code correctly assigns and prepares the output.
Needs to confirm if ArticleHandler::view
hook is still triggered as expected in OJS 3.4.
Best Regards
Darryl