Search Documentation

How to add Tools

Add new tools in Cobalt

Sometimes you need a little PHP code that does something cool for you. Clean some directories or files or records in DB. Whatever, but I have found it is very often demand. Previous Tools plugin system was complicated to create. Now we built something very easy to use and the way you do not lose changes on next update.

All tools ar located in plugins/mint/toolset/tools folder. All you need to do is copy one of those folders inside.

Lets create tool that will extend exparison date for all articles in given section.

1. Structure

Copy folder plugins/mint/toolset/tools/smf to plugins/mint/toolset/tools/extender. Now we have a base for plugin. There are 2 files in that directory.

2. data.json

This file stores your last parameters selected in the form. open it and delete everything and replace with {} empty JSON.

3. icon.png

This is an icon that is shown in the list of the tools. You can use any icon you like here.

4. meta.json

This file contain information about this tool.

	"label": "Extend",
	"description": "Extend expired articles.",
	"height": "500"

You have only 3 parameters here. Label and description are obvious and height set the height of popup when you open tool form. Edit it accordingly.


This file define form that will be shown before you run the tool.

<?xml version="1.0" encoding="utf-8"?>
    <fieldset name="extender" addfieldpath="/libraries/mint/forms/fields">
        <field name="section_id" type="meresourcessection" default="" alias="1" label="Forum Section" global="0" append="" />
        <field name="days" type="text" default="10" label="how many days?" />

I have choosen SMF 2 Forum on purpose. Because it contain example of how to list sections or types in tool form.

Pay attantion that you have to change name property of <fieldset> to the name of your folder. If you wnt to know what other form element types of Cobalt are available look in /libraries/mint/forms/fields folder.


The last file is PHP script itself.

All parameter you seleted in form are available in $params variable.

$app = JFactory::getApplication();
$db  = JFactory::getDbo();
$sql = "UPDATE `#__js_res_record` SET `extime` = `extime` + INTERVAL " . 
    $params->get('days', 10) . " DAY WHERE `extime` < NOW() AND `section_id` = " . 
	$params->get('section_id', 0);

$app->enqueueMessage(JText::_('All records extended'));

That is it.