Disabling add-on dependency does not disable add-on

Arty

Well-known member
I have 2 add-ons: Iconify/Core and Iconify/TemplateModifications.

Iconify/TemplateModification depends on Iconify/Core being installed and it is listed in addon.json like this:
Code:
    "require": {
        "Iconify/Core": [1, "Iconify Core 1.0.0-beta1"]
    },
When both add-ons are installed, if I disable Iconify/Core add-on, it does not disable Iconify/TemplateModifications add-on.

It would be logical to disable add-ons that depend on disabled add-on because otherwise it could break things. In my case Iconify/Core created custom template tags, which were not available once Iconify/Core is disabled, so Iconify/TemplateModifications could not use those tags, but was enabled, which led to errors.
 
I ran across something very similar to this and the solution was to extend the Addon entity _presave function and throw an error if your add-on is enabled..

Code:
if ($this->addon_id == 'Iconify/Core' && $this->isChanged('active') && $this->active == false)
{
    CODE CHECKING IF Iconify/TemplateModifications IS ACTIVE
    THROW ERROR IF IT IS
}

if ($this->addon_id == 'Iconify/TemplateModifications' && $this->isChanged('active') && $this->active == true)
{
    CODE CHECKING IF Iconify/Core IS ACTIVE
    THROW ERROR IF IT IS NOT
}

In your case (and mine) the error should tell the user that the first add-on can't be disabled until the second add-on is disabled. Then the reverse for enabling the second add-on.
 
This is just something we don't attempt to handle automatically, but something that there are tools for so you can do that.

As well as the above, I suspect you'd be able to do it with your AddOn Setup class. If you define a method like this:
PHP:
public function onActiveChange($newActive, array &$jobList)
{
    // do stuff
}
 
Back
Top Bottom