Changing tagit source in OJS3 metadata fields

Hi,

I have been experimenting with OJS 3 and have tried to update my plugins to support it.

One of my plugins connects the CrossRef funder information via their API to the Sponsors field in OJS 2. It is a relatively simple plugin but since OJS 3.0 is already loading tagit to the new Agencies field I can not use my plugin anymore.

After doing some searching in the code I found this template: templates/submission/submissionMetadataFormFields.tpl (https://github.com/pkp/pkp-lib/blob/master/templates/submission/submissionMetadataFormFields.tpl)

Now I can set “source” here and give it the value “http://api.crossref.org/funders”. However, this is all the customization I can do as far as I understand? The problem is that the API is indeed called when writing to the field but instead of the correct form http://api.crossref.org/funders?query=searchedword the request is http://api.crossref.org/funders?term=searchedword&_=1473416294687 and the API of course returns an error.

I do not know where the “term” is hardcoded or if it could be changed? Furhermore, I would like to change some other tagit settings as well, for example the label that is returned by tagit, but that seems to be very difficult using the in-built tagit? In my plugin the returned value from CrossRef is “Name of the agency [DOI]” (I use the DOI elsewhere and my plugin is collecting that data separately). I also could not find any way of adding a tagit source to a metadata field via a plugin? The only way of doing it was to hardcode it to the template file mentioned above which is of course very problematic.

If you have any suggestion on how to customize tagit in specific metadata fields I would be happy to hear.
The simplest solution would probably be to disable tagit in some fields alltogether, but I do not know whether this is possible via a plugin?

Hi @ajnyga,

It sounds like you’ve gotten a good part of the way there by doing a direct modification. Some aspects of OJS will be easier to customize than others – one approach you could use is to write a Smarty postfilter to watch for and rewrite certain snippets of generated HTML. That would permit you to adjust generated markup without modifying the template files.

Regards,
Alec Smecher
Public Knowledge Project Team

Thank you. I will check that. Could not figure out the exact difference between postfilters and output filters (used in sehl plugin), but once I have a preg_replace ready it should be easy to see what works best.

Hi again,

Just one follow-up question to this topic.

Even though I was able to replace the search parameter with a query parameter the CrossRef API is still returning an error. This is because the whole query looks like this:
http://api.crossref.org/funders?query=word*&_=1473762272453

The error is: {"status":"failed","message-type":"validation-failure","message":[{"type":"unknown-parameter","value":"_","message":"Parameter _ specified but there is no such parameter available on any route"}]}

Somewhere along the line the query gets that _ parameter, but where? What is it and is there any way of removing it?

Hi @ajnyga,

I believe JQuery is adding the _ parameter. See for example this StackOverflow post.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Thanks again, added cache: true to the ajax call and works like a charm. I will post the endresult here within a few days if someone else is trying to do the same.

Hi @ajnyga,

Great, thanks!

Regards,
Alec Smecher
Public Knowledge Project Team

Hi,

I see that “a few days” was a bit of an understatement.

I have had a working plugin for some time now. I will publish my CrossRef funder registry plugin in Github as well, but just in case someone is trying to do something similar with some other external API, here are the key elements when adding a remote source to tagit in OJS3. I am happy to hear if something could be done easier.

The hook I use is this. I could not use TemplateManager:display, because the template I need to hook into is a subtemplate.

HookRegistry::register (‘TemplateManager::include’, array(&$this, ‘handleTemplateDisplay’));

In handleTemplateDisplay I have:

$templateMgr =& $args[0];
$params =& $args[1];
$request =& PKPApplication::getRequest();
if (!isset($params[‘smarty_include_tpl_file’])) return false;
switch ($params[‘smarty_include_tpl_file’]) {
case ‘submission/submissionMetadataFormFields.tpl’:
$templateMgr->register_outputfilter(array($this, ‘agenciesFilter’));
break;
}

And in agenciesFilter I use preg_replace:

// Get everything between these two strings…
$startPoint = ‘fieldName: “keywords[en_US-agencies][]”,’;
$endPoint = ‘< /script>’;
// … and replace that with these new parameters:
$newscript = “your tagit parameters here”;

$output = preg_replace(’#(’.$startPoint.’)(.*?)(’.$endPoint.’)#si’, ‘$1’.$newscript.’$3’, $output, 1);

It would be fairly easy to extend that by checking which locales are in use and do preg_replace to all other locales as well.

The interesting thing with

  switch ($params['smarty_include_tpl_file']) {
  	case 'submission/submissionMetadataFormFields.tpl':

Is that it is being run several times when loading a page. I could not figure out why. It does not prevent this approach from working, but I thought that the subtemplate would be called only once.

Of course the optimal solution would be that there would be a hook which a plugin could use to change the tagit parameters in different fields. Then you could for example use an external source of reviewer interests, keywords etc.

1 Like