Skip to main content
page last edited on 8 May 2020

Addon Hooks

Version: 5.5.1

Addon hooks are programming code used to perform certain operations with data in the process of executing the events like addon installation, removal, activation, deactivation and rebuild.

Addon Hooks Overview

  • init - run on every request to XC
  • install - run after the add-on installation
  • enable - run after the add-on is enabled (after install, in case of installation)
  • disable - run after the add-on is disabled
  • remove - run only during deletion of an add-on that cannot be disabled (that has canDisable:false in main.yaml)
  • rebuild - run after every rebuild (after install and enable)
  • upgrade - run during upgrade (before rebuild)

Addon Hook Format

To store hooks, use separate classes that are DI services.

To subscribe to every hook, add a corresponding tag to the service description:

modules/[Author]/[Name]/config/services/hooks.yaml

[Author]\[Name]\LifetimeHook\Init:
tags:
- {name: xcart.lifetime-hook, type: init, method: onInit}
[Author]\[Name]\LifetimeHook\Install:
tags:
- {name: xcart.lifetime-hook, type: install, method: onInstall}
[Author]\[Name]\LifetimeHook\Enable:
tags:
- {name: xcart.lifetime-hook, type: enable, method: onEnable}
[Author]\[Name]\LifetimeHook\Disable:
tags:
- {name: xcart.lifetime-hook, type: disable, method: onDisable}
[Author]\[Name]\LifetimeHook\Rebuild:
tags:
- {name: xcart.lifetime-hook, type: rebuild, method: onRebuild}
[Author]\[Name]\LifetimeHook\Upgrade\UpgradeTo5{major}{minor}build{build}:
tags:
- {name: xcart.lifetime-hook, type: upgrade, method: onUpgrade, version: 5.{major}.{minor}.{build}}

An add-on can have several hook classes, if it is required for a better code readability. For example, upgrade hooks can be moved to a separate class, or every hook can have a separate class.