Plugin creation - Hook not found

Hi

I’m in the process of writing a plugin for our OJS but the callback method is never called.

I made sure that the plugin is activated. Also put an error_log(...) inside the register method to verify that everything worked fine.

Goal of the plugin is to show something on the backend side inside the submission tab.
For this I thought I can register my own hook which I then call from the OJS submission.tpl template file via {call_hook name=...}.

After this did not work I tried with a very generic hook just so I can see if the plugin works at all but even
on the common footer (on the public frontend side) there is no output and the callback is never actually called.

HookRegistry::register('Templates::Admin::Submission::Step1', array($this, 'actionCallback'));
HookRegistry::register('Templates::Common::Footer::PageFooter', array($this, 'actionCallback'));

I then went inside the hook OJS magic and found out that the hook is from the template is successfully calling method smartyCallHook inside ./lib/pkp/classes/template/PKPTemplateManager.inc.php.

Then I proceeded to check for the call method inside the HookRegistry itself and added some debug error_log(...) statements there.

Long story short:
if (!isset($hooks[$hookName])) { }

This if triggers for both of my hooks.

Did I understood something entirely wrong about the hook concept?
Maybe one of you can help me out.

Many thanks in advance

Hi @KRONWALLED,

Is your plugin registered with OJS? This normally happens during the plugin installation process, but if you’re writing your own plugin from scratch, you won’t have gone through that.

Make sure your version.xml descriptor is accurate (e.g. the product tag corresponds to the name of the directory your plugin code is placed within). Then, to register the plugin, run

php lib/pkp/tools/installPluginVersion.php path/to/plugin/version.xml

This should create an entry in the versions table in the database for your plugin.

Regards,
Alec Smecher
Public Knowledge Project Team

2 Likes

@asmecher Oh my… You just made my day.
I didn’t knew that I had to manually register the plugin.

Thanks a lot :slight_smile:
Works as intended now.

Well, that’s freaking useful. Now I need to update all my plugin documentation.

1 Like