Use "getOption('baseColour');" in generic plugin

Hi to all members,

I am developing a generic plugin and would like to use the baseColour at one point, which is used for the main background of all journals of an instance. This can be easily retrieved in a theme plugin via $baseColour = $this->getOption('baseColour'); (ojs/ at 2f4aed2299aca4b660ce5c5af4a4c210e1e9e93a · pkp/ojs · GitHub, pkp-lib/ at 559edb8599e688c1f520a9d68d8ac526f90081b4 · pkp/pkp-lib · GitHub). Or also via the REST API using http://localhost:8000/_/api/v1/contexts/1/theme.

However, since I am not in the DefaultThemePlugin class or ThemePlugin class but in a subclass of GenericPlugin I cannot access the corresponding $this to get to the baseColor. How is it anyway possible that I can read the variable in a generic plugin?

I am currently using version pulled from OJS main branch on github.

I am very glad about any help!

Hi @tnier01,

I would use a theme plugin for this as it provides easy access to the appearance form. I suspect the idea is to add the option there, right?
Generic Plugins usually implement own form, e.g.: Plugin Settings - Plugin Guide for OJS and OMP and live example JATSParserPlugin/ at main · Vitaliy-1/JATSParserPlugin · GitHub.

Both type of plugins can hook into other forms to extend the list of available options there: Example - Add Custom Fields - Plugin Guide for OJS and OMP but it requires much more effort to implement

Hi @Vitaliy,

thanks for the idea but according to my understanding I have to use a generic plugin because I use different hooks and want to change the application and its database at different places.

I don’t want to give the user an additional option to customize the baseColour, I just want to get this colour to use it in a html galley created by the plugin. Is there a possibility to get the variable baseColour for example with the function getOption in a generic plugin like explained here Use "getOption('baseColour');" in generic plugin or alternatively by a direct request to the database?

Thanks in advance for all suggestions.

I’d still use the theme plugin. There is at least 1 task related to the front-end appearance that the plugin should do. Hooks are the same.

I’m afraid that don’t understand the idea. If just using the color in HTML galleys, without exposing it to a user, wouldn’t be easier just to upload a custom CSS through a dashboard?

With the implementation of the generic plugin I am currently developing, many things are already implemented that change OJS, such as an extension of the submission metadata input with the hook Templates::Submission::SubmissionMetadataForm::AdditionalMetadata or adding additional fields to the database. The issue with the baseColour should be integrated in this plugin. So would these steps also be possible with a thematic plugin?
If I understand the documentation here (Plugin Categories - Plugin Guide for OJS and OMP) correctly, a generic plugin should be used for such changes. Since code has already been implemented accordingly, it would be the easiest to find a way to get the baseColour in a generic plugin.

So is there a way that works the way I described here?

Yes, if I just want to use a single static color that would be the easiest of course. But the color in the galley should be updated accordingly when the baseColour in the OJS application is changed by the user. I hope it is a bit clearer this way!

Try something like:

$pluginSettingsDAO = DAORegistry::getDAO('PluginSettingsDAO');
$context = PKPApplication::getRequest()->getContext();
$contextId = $context ? $context->getId() : 0;
$defaultPluginSettings = $pluginSettingsDAO->getPluginSettings($contextId, 'DefaultThemePlugin');

to retrieve Default Theme Plugin settings, like baseColour, as associative array [setting name => setting value]

Hi @Vitaliy,

thanks for the idea, I tried it right away, it works for me. However, the query is now limited to the DefaultThemePlugin. Is there a similar possibility to query the baseColour independent of the currently installed ThemePlugin?
Or do I understand something wrong here and the baseColour is not definable for all but only for some ThemePlugins as it is for example the case for the DefaultThemePlugin?

Thanks in advance for all suggestions.

It’s defined on per theme basis:

But other themes may use different names for such options, e.g., classic: classic/ at c52d63ede235767d0ed22b9a586c7bf1105fdb9d · pkp/classic · GitHub

1 Like

Thanks @Vitaliy for the detailed explanation, that makes it clear for me now!