Hook suggestion

Hi @asmecher ,

In OJS3, it would be nice to have a hook in the Schedule for publication form.

We have a national label for peer reviewed articles and that form would be the ideal place to attach it to the article metadata. Of course I can use the submission metadata form as well, but I think that the label is closer to the kind of metadata that the permissions are.

Hi @ajnyga,

There is a hook in that form, I think – if you look at the parent Form class it uses a little bit of basic introspection to find out what class it’s implementing, then calls some hooks automatically based on that. The form you’re looking at triggers issueentrypublicationmetadataform::display, for example, when it’s displayed.

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks

With that hook, if I would want to add a new form field there, would I have to change the whole form template?

Edit: or is “TemplateManager::display” actually better?

The only examples I can find using this are either adding javascripts, adding header data, using smarty filters or chancing the whole template.

What I would like to do is to use the same method that you can use with the template hooks ie. add a template to an existing template. But I guess that is not an option here?

Hi @ajnyga,

Smarty isn’t especially easy to work with if you want to inject some code into an existing template. It’s possible, however – I don’t think we have any examples of this in OJS3 at the moment, but OJS2 does include some (e.g. the Dataverse plugin). Check out Smarty’s register_outputfilter function. This allows you to register a filter on Smarty markup; you could watch for a particular form field e.g. by ID, then inject another field after that element closes.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi, thanks @asmecher,

I actually already figured out that the filters are the only option here since the hook is not in the template.

I can post the solution I used here on Monday.

This is the code I used. I noticed that unlike with the template hooks, I could not use initdata (https://github.com/pkp/ojs/blob/master/plugins/generic/openAIRE/OpenAIREPlugin.inc.php#L39). Instead I had to assign the existing value before injecting the custom field to the form. But this seems to work fine as well.

This hooks to the “schedule for publication” form, but basically would likely work with any form without a template hook.

1 Like