Plugin developpment : how to execute a plugin function with à button in CB plugin configuration form

10 years 4 months ago - 10 years 4 months ago #238813 by roland_d_alsace
Hi.

In my plugin configuration form i want to have à button, wich run one of my plugin function.
After execute my function i want to return in my plugin configuration form (if possible with possibility of displaying a message to the administrator).

It's for actualise elements of my component tables, with CB tables elements, and with my plugin parameters, or vice-versa.
One exemple, i have a component installed, and later i install CB.
After installing my specific CB plugin, and after the administrator define CB fields, with corespondance with my components fields defined in my plugin parameters,
i want the the administrator can synchronise the 2 components tables (the CB comprofiler table and my own component user table).
This is one sample but they ara a lot of others.

Have you an idea how to do this (plugin config form button -> execute plugin function -> return to plugin config form) ?

If it's not possible without hacking CB framework, a 2nd soluce is to execute my function in my Joomla component admin panel.
But if i'm on my Joomla component, the CB framework is not loaded and i need to get my CB plugin parameter...
Have you an 2nd idea for this ?

Regards...
...and mery christmas :)

Please Log in to join the conversation.

10 years 4 months ago - 10 years 4 months ago #238834 by krileon
Yes, this is possible. You need to use a custom backend display though. See CB Blogs, CB Articles, etc.. on how to have a custom backend. Review the admin files and their XML files carefully.

To get your plugins parameters without loading CB you'll need to query the database then parse out the INI string (soon to be JSON with CB 2.0). It's better to just use API though.

For example you can render a button by outputting a custom XML parameter to display however you like as follows.

XML:
<param name="my_button" type="custom" class="myPluginClass" method="loadButton" default="" label="My Button" description="" />

PHP:
class myPluginClass extends cbFieldHandler {

	public function loadButton( $name, $value, $control_name ) {
		return '<button type="button" class="button" onclick="alert(\'works\');">button</button>';
	}
}

Ideally your button would go to a backend component page (review CB Blogs, etc.. on how to make one of those.. you need the admin file) using the below URL structure.

index.php?option=com_comprofiler&task=editPlugin&cid=PLUGIN_ID_HERE&action=button

Really you don't need &action and you can use whatever you like to trigger what function should occur in your admin display.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: roland_d_alsace

Please Log in to join the conversation.

10 years 4 months ago - 10 years 4 months ago #238848 by roland_d_alsace
Thanks Krileon.

I have found the method for aces to my CB plugin parameters on my Joomla Componants.

After testing if cb and my plugin is installed i make this :
include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
include_once( JPATH_ADMINISTRATOR . "/components/com_comprofiler/plugin.class.php");
$_PLUGINS->loadPluginGroup('user');
cbimport( 'cb.database' );
foreach ($_PLUGINS->_plugins as $pluginid => $plugin) {
    if ($plugin->element=="my_plugin_name" || $plugin->folder=="my_plugin_folder"){
        $pluginClassInstance=&$_PLUGINS->getInstanceOfPluginClass( 'my_plugin_class', $pluginid );
        $pluginClassInstance->_loadParams( $pluginid, null );
        $pluginClassInstance->element=$_PLUGINS->_plugins[$pluginid]->element;
	$params=$pluginClassInstance->params;
	return $params;
    }
}
return false;

I think it's better than directly parsing in the database, especialy if CB team us Json in next CB release.

However, i will also use you idea, but can you precise :

Really you don't need &action and you can use whatever you like to trigger what function should occur in your admin display.


This means that i need to test de Jrequestvar "action" in my plugin to execture the good function ?

And how can i return to plugin admin after execute my function (i make a standard joomla redirection, with standard Joomla message ?)

Thanks & Regards.

Please Log in to join the conversation.

10 years 4 months ago #238852 by krileon

I think it's better than directly parsing in the database, especialy if CB team us Json in next CB release.

Yup, that's best case usage for now. Once CB 2.0 is stable and released you'll be able to just use the below.

global $_PLUGINS;

$_PLUGINS->loadPluginGroup( 'user' );

$plugin		=	$_PLUGINS->getLoadedPlugin( 'user', 'PLUGIN_ELEMENT_HERE' );
$plugin->params	=	$_PLUGINS->getPluginParams( $plugin );

This means that i need to test de Jrequestvar "action" in my plugin to execture the good function ?

No, check CB Blogs admin.cbblogs.php file. You need a similar file for your plugin. This allows your plugin to have an admin class and the function editPluginView will receive your request data. Another option is add the synchronize feature to your component it self and just have your button link to it.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.214 seconds

Facebook Twitter LinkedIn