Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can onExtensionBeforeInstall be used to prevent an extension from being installed
    Joomla Events


Can onExtensionBeforeInstall be used to prevent an extension from being installed


Yes, the `onExtensionBeforeInstall` event in Joomla can be used to prevent an extension from being installed.

The search results provide an example of how this can be done:

php
public function preflight($type, $parent){
    // Return true if version to be installed is higher
    if (!$this->isHigherVersion($parent)){
        $msg = "<p>Error msg.</p>";
        JLog::add($msg, JLog::WARNING, 'jerror');
        return false;
    }
}

In this example, the `preflight` method is overridden in the installer script. This method is called before the installation process begins.

The code checks if the version of the extension being installed is higher than the currently installed version using the `isHigherVersion` method. If the new version is not higher, it logs an error message and returns `false`, which will prevent the installation from proceeding.

By returning `false` from the `preflight` method, the installation process is stopped before any files are extracted or changes are made to the system. This allows the developer to perform validation checks and prevent the installation if necessary.

The search results also mention that this approach can be used to stop the update or uninstallation process as well, not just installation.

So in summary, yes, the `onExtensionBeforeInstall` event, specifically the `preflight` method in the installer script, can be used to programmatically prevent an extension from being installed in Joomla if certain conditions are not met.

Citations:
[1] https://fliphtml5.com/eztvv/yypz/Learning_Joomla_3_Extensions_Development/
[2] https://stackoverflow.com/questions/25372273/how-to-enable-protected-extensions
[3] https://joomla.stackexchange.com/questions/20982/how-stop-update-installation-by-install-script-and-mantain-actual-folder
[4] https://docs.joomla.org/Help310:Extensions_Extension_Manager_Install
[5] https://docs.joomla.org/installing_an_extension