Calling plugin function from template


On the mission to develop a plugin I ran against a wall.

What I got:

  • A plugin which shows a button on the submission workflow
  • A button which shows a modal screen
  • A modal screen which sends data to a backup server which optimizes and merges submission files into
    one PDF via libreoffice
  • A backend server which converts files into pdf and merges all files into one.

What I miss:

  • A basic functionality to listen on an event

I’m sending the data to the backend server via a jQuery ajax call.
Server processes the given input and returns HTTP 200.

In the .done() handler from jQuery I want to react to the finished conversion / merge.
For this I created another method in my plugin which inserts the newly created file into the database and moves the file into the correct directory with the correct filename.

I tried to call a hook inside the .done() but then realized a hook gets resolved immediately after page load which sounds pretty logical as Smarty renders everything already …

Is there another way to call my function after the request to my backend finishes?


    method: "POST",
    contentType: "application/json",
    url: "http://server.local/converter/convert",
    data: JSON.stringify({ 'files' : idList, 'apiKey' : 'xxx' })
.done(function(response) { 
    // Here I need to call my function inside the plugin code

Thanks in advance :slight_smile:

Within your jQuery .done() event, you will need to make an additional AJAX call to an OJS handler (or UA redirect to an OJS handler).

It almost sounds like you were initially expecting to be able to run the PHP inline from the javascript. If so, be sure to clearly visualize where each bit of code is running: the javascript on the user’s browser, and the PHP on the webserver.

If you can share a link to your code, we can perhaps offer more specific advice.

1 Like

Just wanted to update this thread.
I created a second gateway based plugin which gets a request whenever the first one goes through successfully.

Its working now.

Now one question came up to me:
Is it better to still use gateway plugins or should we make the switch to the new REST api?

Thanks alot anyway!

The existing documentation on gateway plugins is old and very scant.

Based on your description, I would have expected your plugin to be a Generic Plugin, where you can implement multiple Handlers within the single plugin. These plugins should be able to interact with and extend the new REST API, though I don’t have a good example of that currently.

I ended up throwing the gateway plugin away and created a new REST endpoint in the application.
Looks good so far and even authorization was easy as pie.

When I cleaned up the code and battle-tested it a bit I will make the plugin and the REST part available on Github.

Thanks for your help and great work :slight_smile:

1 Like