Pulling information from Journal Masthead

Using this documentation on custom fields I managed to add a field on journal publishing details.
I needed to customize a theme, and so I added the functions inside the ChildThemePlugin.inc.php file for my theme, and it worked fine for adding the field itself, however calling the object in my frontend .tpl files yielded nothing. both $currentContext->getLocalizedData('objectName') and $journal->getLocalizedData('objectName') showed nothing. I’m looking for a way to display each journal’s property value that I have in my journal masthead inside the indexSite.tpl file (main page).
I went through some of the API Reference however I got lost by the sheer volume of information, and with me being a beginner when it comes to the workings of OJS I didn’t know where to start.
I noticed some of the journal values were displayed using getLocalizedData() or other similar functions which seem to be called from DataObject.inc.php (though I might be wrong) but I have no idea how to implement it.
Maybe my getLocalizedData() works (either with $currentContext or $journal), and my addToSchema() isn’t working properly.
Any insight would be appreciated.

P.S.
Alternatively, if grabbing the pre-existing Publisher field from the Journal masthead and displaying it in the frontend would be easier, I’d appreciate if anyone could let me know a way to do that.

Hi @ComfyBlanket, can you share your custom code? Also, what version of OJS are you using?

You should be able to show this on the indexSite.tpl, inside of the loop where the journals are listed, with the following:

{$journal->getData('publisherInstitution');

1 Like

Here’s the plugin.inc.php file for my theme. Adding the “Publ” label as well as the textbox under it through addToForm() seems to work fine, but I cannot seem to call it on my index site with the testPublisher property from addToSchema(). I’ve only been looking at how ojs works for a few days so far so maybe I’m doing something very wrong here.
Also, $journal->getData('publisherInstitution') works well and solves what I needed, though it would still be nice to know how I could add (working) fields in the journal masthead that I can get information from.
Edit: I’m currently on OJS 3.3.0.3 and may upgrade to 3.3.0.4 once I’m done editing this plugin.

/**
 * @file plugins/themes/default/DefaultManuscriptChildThemePlugin.inc.php
 *
 * Copyright (c) 2014-2020 Simon Fraser University
 * Copyright (c) 2003-2020 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class DefaultManuscriptChildThemePlugin
 * @ingroup plugins_themes_default_manuscript
 *
 * @brief Default theme
 */
import('lib.pkp.classes.plugins.ThemePlugin');

class DefaultManuscriptChildThemePlugin extends ThemePlugin {
	/**
	 * Initialize the theme's styles, scripts and hooks. This is only run for
	 * the currently active theme.
	 *
	 * @return null
	 */
	public function init() {
	    HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));

		// Initialize the parent theme
		$this->setParent('defaultthemeplugin');

		// Add custom styles
		$this->modifyStyle('stylesheet', array('addLess' => array('styles/index.less')));

		// Remove the typography options of the parent theme.
		$this->removeOption('typography');
		$this->removeOption('useHomepageImageAsHeader');

		// Add the option for an accent color
		$this->addOption('accentColour', 'FieldColor', [
			'label' => __('plugins.themes.defaultManuscript.option.accentColour.label'),
			'description' => __('plugins.themes.default.option.colour.description'),
			'default' => '#F7BC4A',
		]);

		// Dequeue any fonts loaded by parent theme
		if (method_exists($this, 'removeStyle')) {
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
			$this->removeStyle('font');
		}
		
        $this->addOption('journalExtra', 'FieldText', [
			'type' => 'text',
  			'label' => __('plugins.themes.defaultManuscript.options.journalExtra.label'),
		]);
		$journalExtra= $this->getOption('journalExtra');

		// Start with a fresh array of additionalLessVariables so that we can
		// ignore those added by the parent theme. This gets rid of @font
		// variable overrides from the typography option
		$additionalLessVariables = array();

		// Update colour based on theme option from parent theme
		if ($this->getOption('baseColour') !== '#1E6292') {
			$additionalLessVariables[] = '@bg-base:' . $this->getOption('baseColour') . ';';
			if (!$this->isColourDark($this->getOption('baseColour'))) {
				$additionalLessVariables[] = '@text-bg-base:rgba(0,0,0,0.84);';
			}
		}

		// Update accent colour based on theme option
		if ($this->getOption('accentColour') !== '#F7BC4A') {
			$additionalLessVariables[] = '@accent:' . $this->getOption('accentColour') . ';';
		}

		if ($this->getOption('baseColour') && $this->getOption('accentColour')) {
			$this->modifyStyle('stylesheet', array('addLessVariables' => join('', $additionalLessVariables)));
		}
	}
	
	public function register($category, $path, $mainContextId = null) {
		$success = parent::register($category, $path);
		if ($success && $this->getEnabled()) {

			// Use a hook to extend the context entity's schema
			// HookRegistry::register('Schema::get::context', array($this, 'addToSchema'));

			// Use a hook to add a field to the masthead form in the journal/press settings.
			HookRegistry::register('Form::config::before', array($this, 'addToForm'));
		}
		return $success;
	}
	public function addToSchema($hookName, $args) {
		$schema = $args[0];
		$schema->properties->testPublisher = (object) [
			'type' => 'string',
			'apiSummary' => true,
			'multilingual' => true,
			'validation' => ['nullable']
		];

		return false;
    }
	/**
	 * Extend the masthead form to add an institutionalHome input field
	 * in the journal/press settings
	 */
	public function addtoForm($hookName, $form) {

		// Only modify the masthead form
		if (!defined('FORM_MASTHEAD') || $form->id !== FORM_MASTHEAD) {
			return;
		}

		// Don't do anything at the site-wide level
		$context = Application::get()->getRequest()->getContext();
		if (!$context) {
			return;
		}

		// Add a field to the form
		$form->addField(new \PKP\components\forms\FieldText('testPublisher', [
			'label' => 'Publ',
			'groupId' => 'publishing',
			'value' => $context->getData('testPublisher'),
		]));


		return false;
	}
	    public function loadTemplateData($hookName, $args) {
		// Retrieve the TemplateManager
		$templateMgr = $args[0];


		// Attach a custom piece of data to the TemplateManager
		if($this->getOption('journalExtra')) {
			$templateMgr->assign('journalExtra', $this->getOption('journalExtra'));
		}

		return false;
	}

	/**
	 * Get the display name of this plugin
	 * @return string
	 */
	function getDisplayName() {
		return __('plugins.themes.defaultManuscript.name');
	}

	/**
	 * Get the description of this plugin
	 * @return string
	 */
	function getDescription() {
		return __('plugins.themes.defaultManuscript.description');
	}
}

Bumping for an answer to retrieving the custom field information inside journal publishing details