Launchpad
Launchpad
Launchpad
  • Introduction
  • General
    • Installation
    • Creating a subscriber
    • Contributing
  • Tutorials
    • Beginner documentation
      • Beginner handbook
        • Creating subscribers
        • Wiring subscribers
        • Installing local environment
        • Adding front-end
        • Building the plugin
      • Plugin life circle
        • Activation
        • Deactivation
        • Uninstall
    • Starting with the framework
    • Migrating to Launchpad
    • Notions
      • Framework concepts
        • Inversion of control
        • Subscribers
        • Dispatcher
      • Good practices
        • Hooks
          • Preventing magic constants
          • Decouple features
          • Sanitize filters output
      • Testing
        • Organize tests
  • CLI
    • Commands
    • Creating a command
  • Testing
    • Unit test
    • Fixtures
    • Integration test
  • Container
    • Architecture
    • Parameters
    • Providers
    • Auto wiring
    • Manual wiring
    • Activation/Deactivation
    • Inflectors
  • Modules
    • Definition
    • Listing
      • Action Scheduler
      • BerlinDB
      • Bus
      • Options
      • Renderer
      • Logger
      • Uninstaller
      • Filesystem
      • Front-end
      • Hook extractor
    • Creating a module
Powered by GitBook
On this page
  1. Tutorials
  2. Beginner documentation
  3. Plugin life circle

Deactivation

PreviousActivationNextUninstall

Last updated 5 months ago

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 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 using interface and trait:

class ServiceProvider extends AbstractServiceProvider implements HasDeactivatorServiceProviderInterface {
	use HasDesactivatorServiceProviderTrait;
	
	/**
	 * Define your services.
	 *
	 * @return void
	 */
	protected function define() {

	}
}
class ServiceProvider extends AbstractServiceProvider implements HasDeactivatorServiceProviderInterface {
	use HasDesactivatorServiceProviderTrait;
	
	protected function define() {
		$this->register_deactivator(MyDeactivator::class);
	}
}

It is then possible to have access to the inside :

use @deactivate annotation
add the necessary logic into the provider
HasDeactivatorServiceProviderInterface
HasDesactivatorServiceProviderTrait
register_deactivator method to register our deactivator
the define method