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

Activation

PreviousPlugin life circleNextDeactivation

Last updated 8 months ago

CtrlK

The activate logic is some logic that execute when the plugin is activated.

This happens in two cases:

  • when the plugin installs.

  • when the plugin got disabled and is re-enabled.

It is possible to use that state to initialize the plugin:

  • By creating tables.

  • By creating initial configurations.

Creating an activate logic

In Launchpad, to create a logic which will be executed when the plugin is activated, we need to use an Activator.

To create an activator, any class can be used as the only requirement is to use the @activate annotation inside the docblock of at least one of the methods:

class MyActivator {
    /**
    * @activate
    */
    public function register_options() {
        
    }
}

Once the activator 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 HasActivatorServiceProviderInterface interface and HasActivatorServiceProviderTrait trait:

class Provider extends AbstractServiceProvider implements HasActivatorServiceProviderInterface {
   use HasActivatorServiceProviderTrait; 
   
   public function define() {

   }
} 

It is then possible to have access to the register_activator method to register our activator inside the define method:

class Provider extends AbstractServiceProvider implements HasActivatorServiceProviderInterface {
   use HasActivatorServiceProviderTrait; 
   
   public function define() {
    $this->register_activator(MyActivator::class);
   }
}