I created content plugin to extend category option. This plguin could add second image to category, it works well. But when I uninstall this plugin, the image is still in the database.
What I want is: the data is also removed when the plugin is uninstalled. How?
I created 3 files:
- categorydrawing.php
- categorydrawing.xml
- categorydrawingimage.xml
Code in categorydrawing.php
<?php
// no direct access
defined ('_JEXEC') or die;
class plgContentCategoryDrawing extends JPlugin
{
/**
* Load the language file on instantiation.
* Note this is only available in Joomla 3.1 and higher.
* If you want to support 3.0 series you must override the constructor
*
* @var boolean
* @since <1.0>
*/
protected $autoloadLanguage = true;
/**
* Prepare form and add my field.
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since <1.0>
*/
function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$option = $app->input->get('option');
switch($option)
{
case 'com_categories' :
if ($app->isClient('administrator'))
{
JForm::addFormPath(__DIR__);
$form->loadFile('categorydrawingimage', false);
}
return true;
}
return true;
}
}
?>
Codes in categorydrawing.xml
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" group="content" method="upgrade">
<name>Category Drawing</name>
<description>To add drawing to category</description>
<files>
<filename plugin="categorydrawing">categorydrawing.php</filename>
<filename>categorydrawingimage.xml</filename>
</files>
</extension>
Codes in categorydrawingimage.xml
<?xml version="1.0" encoding="UTF-8"?>
<form>
<config>
<fields name="params">
<fieldset name="drawing_image_short_description" label="Drawing Image and Description">
<field
name="drawing_image"
type="media"
label="Drawing Image"
/>
<field
name="drawing_image_alt"
type="text"
label="Drawing Image Description (Alt Text)"
/>
</fieldset>
</fields>
</config>
</form>