Deactivation
The deactivate logic is some logic executed each time the plugin got disabled.
It is possible to use that state to interrupt the plugin:
By cancelling crons.
By updating the settings.
Create a deactivate logic
In Launchpad, to create a logic to be executed when the plugin disabling, we need to create a deactivator.
To create a deactivator, any class can be used as the only requirement is to use @deactivate
annotation inside the docblock of at least one of the methods:
class MyDeactivator {
/**
* @deactivate
*/
public function unregister_options() {
}
}
Once the deactivator class is created, it needs to be registered on a service provider to be loaded.
For that it is important to first add the necessary logic into the provider using HasDeactivatorServiceProviderInterface
interface and HasDesactivatorServiceProviderTrait
trait:
class ServiceProvider extends AbstractServiceProvider implements HasDeactivatorServiceProviderInterface {
use HasDesactivatorServiceProviderTrait;
/**
* Define your services.
*
* @return void
*/
protected function define() {
}
}
It is then possible to have access to the register_deactivator
method to register our deactivator inside the define
method:
class ServiceProvider extends AbstractServiceProvider implements HasDeactivatorServiceProviderInterface {
use HasDesactivatorServiceProviderTrait;
protected function define() {
$this->register_deactivator(MyDeactivator::class);
}
}
Last updated