Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon OnExtensionAfterInstall usage example
    Joomla Events


OnExtensionAfterInstall usage example


The onExtensionAfterInstall event in Joomla is used to perform actions after an extension has been installed. Here is an example of how to use this event:

Example Plugin

php
<?php
defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Application\CMSApplication;

class PlgExtensionExample extends CMSPlugin
{
    public function onExtensionAfterInstall($installer, $eid)
    {
        // Get the extension type (component, module, plugin, etc.)
        $type = $installer->get('type');

        // Get the extension name
        $name = $installer->get('name');

        // Perform some action after the extension is installed
        $app = CMSApplication::getInstance('site');
        $app->enqueueMessage("The $type '$name' has been installed.", 'success');
    }
}

This example plugin listens for the onExtensionAfterInstall event and when triggered, it retrieves the type and name of the installed extension, then displays a success message in the Joomla site application.[1][2][4]

The onExtensionAfterInstall event provides the $installer object, which contains information about the installed extension, such as its type, name, and other metadata. This allows you to perform custom actions based on the installed extension.[3][5]

Citations:
[1] https://forum.joomla.org/viewtopic.php?t=985084
[2] https://github.com/joomla/joomla-cms-examples/blob/master/plugins/extension/example/example.php
[3] https://manual.joomla.org/docs/next/building-extensions/install-update/install/install-process/
[4] https://joomla.stackexchange.com/questions/24335/simple-plugin-to-check-folder-contents-on-component-update
[5] https://github.com/civicrm/civicrm-joomla/blob/master/admin/plugins/civicrmsys/civicrmsys.php