Page 1 of 1

Identify if the plugin is enabled or not

Posted: Wed Jun 12, 2019 3:36 am
by jemiris
Hi,

Can you tell me is there any possible way to capture the where the plugin is enabled or not :?:

My problem:
i would like the add the custom button in the form when the plugin enbled only not always :?:

Re: Identify if the plugin is enabled or not

Posted: Wed Jun 12, 2019 11:42 pm
by amosbatto
Create a hidden field in your Dynaform associated with the variable "pluginLoaded".
Then create the following trigger:
Code: Select all
// change myNamePlugin to the name of your plugin's class:
if (class_exists("myNamePlugin")) {
   @@pluginLoaded = 'yes';
}
Set this trigger to fire before the Dynaform.

Then add the following JavaScript to your Dynaform:
Code: Select all
if ( $("#pluginLoaded").getValue() == 'yes') {
    $("#myButton").show();
}
else {
    $("#myButton").hide();
}

Re: Identify if the plugin is enabled or not

Posted: Thu Jun 13, 2019 3:25 am
by jemiris
Thanks for information if it's in the js script page in my plugin how to do that :?:
I have done in php page as you said i could not do for js page. How to check the class exists and enable the button :?:

Re: Identify if the plugin is enabled or not

Posted: Thu Jun 13, 2019 6:06 pm
by amosbatto
If your plugin defines a REST endpoint, then you can use $.ajax() or XMLHttpRequest.send() to try to call that REST endpoint and check if the REST endpoint exists. If not, then the class wasn't loaded.

Which .js file? The ProcessMaker PHP framework has ways to set a variable in a .js file when loading a page.

Re: Identify if the plugin is enabled or not

Posted: Fri Jun 14, 2019 12:46 am
by jemiris
Not i dont use REST API :idea: . But i have file called jemirisApplication.js in the plugin directectory. So can i capture where the plugin is enbled in the js file. Any example that shows that whether the plugin is enabled or not :?:

Re: Identify if the plugin is enabled or not

Posted: Fri Jun 14, 2019 6:26 pm
by amosbatto
If you are talking about your own custom JavaScript files that you created, then you have to figure out how to set the variables yourself. For example, you can use PHP to check if the class exists and then add statements like this when writing the HTML of the page:
Code: Select all
if (class_exists("myNamePlugin")) {
   print "<script> var classXLoaded = 'yes';</script>";
}
else {
   print "<script> var classXLoaded = 'no';</script>";
}
Or you could create a hidden field in the HTML page:
Code: Select all
if (class_exists("myNamePlugin"))
   $val = 'yes';
else
   $val = 'no';

print "<input id=\"classXLoaded\" name=\"classXLoaded\" type=\"hidden\" value=\"$val\">";
I don't know why you are having to check this. If your JavaScript file is in a plugin, then the plugin's class file was loaded if you are executing its JavaScript file.

Your plugin's class is always loaded as long as you enabled the plugin under Admin > Plugins > Plugin Manager.
If you have other classes inside your plugin, then add require statements in the plugin's setup() function to make sure that they are loaded as well.