Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Are there any examples of using onExtensionBeforeInstall to block specific extensions


Are there any examples of using onExtensionBeforeInstall to block specific extensions


There are no direct examples in the search results of using `onExtensionBeforeInstall` to block specific extensions from being installed in Joomla. However, the results do provide some relevant information:

Preventing Installation

The search results mention that the `onExtensionBeforeInstall` event can 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.

An example is provided of overriding the `preflight` method in the installer script to perform validation checks:

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;
    }
}

By returning `false` from this method, the installation process is stopped before any changes are made to the system. This allows the developer to prevent installation if certain conditions are not met.

Disabling Extensions

While not directly related to `onExtensionBeforeInstall`, the search results also mention that you can disable specific extensions in Joomla by removing their update sites:

> In Extensions > Manage > Update sites you can disable any of the update sites relevant to the extension you're referring to in your post.

So in summary, while there are no explicit examples of using `onExtensionBeforeInstall` to block specific extensions, the search results indicate that this event can be used to prevent installation by performing validation checks and returning `false` from the `preflight` method. Disabling extensions can also be done by removing their update sites.

Citations:
[1] https://fliphtml5.com/eztvv/yypz/Learning_Joomla_3_Extensions_Development/
[2] https://docs.joomla.org/Help310:Extensions_Extension_Manager_Install
[3] https://stackoverflow.com/questions/25372273/how-to-enable-protected-extensions
[4] https://github.com/joomla/joomla-cms-examples/blob/master/plugins/extension/example/example.php
[5] https://forum.joomla.org/viewtopic.php?t=925396