1

I am working on a custom component. The component has some component options, using the standard config.xml file and saving it to the extensions table.

But what if I need to execute a custom script when saving the component configs? Depending on the settings of the component, I want to make some changes in the components db tables.

Is there a way provided by Joomla to add a script to the save event for component configs?

I'm still very new to Joomla component building. Any advice is most welcome!

Thanks

1
  • Welcome to JSE, please take the tour. Feb 10, 2020 at 12:28

1 Answer 1

1

Create an extension plugin with onExtensionAfterSave event.

defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Registry\Registry

class PlgExtensionExample extends CMSPlugin
{
    public function onExtensionAfterSave($context, $table, $isNew)
    {
        // Check that we're modifying the correct component.
        if ($context !== 'com_config.component' || $table->element !== 'com_content')
        {
            return;
        }

        // New component params.
        $params = new Registry($table->params);

        // Your code here.
    }
}

Creating a Plugin for Joomla

1
  • Great, thanks, will try this.
    – TVBZ
    Feb 10, 2020 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.