Added method onStartup() for plugins
This commit is contained in:
@@ -62,7 +62,7 @@ abstract class Base extends \Kanboard\Core\Base
|
|||||||
{
|
{
|
||||||
$container = $this->container;
|
$container = $this->container;
|
||||||
|
|
||||||
$this->container['dispatcher']->addListener($event, function () use ($container, $callback) {
|
$this->dispatcher->addListener($event, function () use ($container, $callback) {
|
||||||
call_user_func($callback, $container);
|
call_user_func($callback, $container);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ abstract class Base extends \Kanboard\Core\Base
|
|||||||
/**
|
/**
|
||||||
* Get plugin name
|
* Get plugin name
|
||||||
*
|
*
|
||||||
* This method should be overrided by your Plugin class
|
* This method should be overridden by your Plugin class
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return string
|
||||||
@@ -83,7 +83,7 @@ abstract class Base extends \Kanboard\Core\Base
|
|||||||
/**
|
/**
|
||||||
* Get plugin description
|
* Get plugin description
|
||||||
*
|
*
|
||||||
* This method should be overrided by your Plugin class
|
* This method should be overridden by your Plugin class
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return string
|
||||||
@@ -96,7 +96,7 @@ abstract class Base extends \Kanboard\Core\Base
|
|||||||
/**
|
/**
|
||||||
* Get plugin author
|
* Get plugin author
|
||||||
*
|
*
|
||||||
* This method should be overrided by your Plugin class
|
* This method should be overridden by your Plugin class
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return string
|
||||||
@@ -109,7 +109,7 @@ abstract class Base extends \Kanboard\Core\Base
|
|||||||
/**
|
/**
|
||||||
* Get plugin version
|
* Get plugin version
|
||||||
*
|
*
|
||||||
* This method should be overrided by your Plugin class
|
* This method should be overridden by your Plugin class
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return string
|
||||||
@@ -122,7 +122,7 @@ abstract class Base extends \Kanboard\Core\Base
|
|||||||
/**
|
/**
|
||||||
* Get plugin homepage
|
* Get plugin homepage
|
||||||
*
|
*
|
||||||
* This method should be overrided by your Plugin class
|
* This method should be overridden by your Plugin class
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return string
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ class Loader extends \Kanboard\Core\Base
|
|||||||
Tool::buildDICHelpers($this->container, $instance->getHelpers());
|
Tool::buildDICHelpers($this->container, $instance->getHelpers());
|
||||||
|
|
||||||
$instance->initialize();
|
$instance->initialize();
|
||||||
|
|
||||||
|
if (method_exists($instance, 'onStartup')) {
|
||||||
|
$this->dispatcher->addListener('app.bootstrap', array($instance, 'onStartup'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->plugins[] = $instance;
|
$this->plugins[] = $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ Available methods from `Kanboard\Core\Plugin\Base`:
|
|||||||
- `getPluginDescription()`: Should return plugin description
|
- `getPluginDescription()`: Should return plugin description
|
||||||
- `getPluginHomepage()`: Should return plugin Homepage (link)
|
- `getPluginHomepage()`: Should return plugin Homepage (link)
|
||||||
- `setContentSecurityPolicy(array $rules)`: Override default HTTP CSP rules
|
- `setContentSecurityPolicy(array $rules)`: Override default HTTP CSP rules
|
||||||
|
- `onStartup()`: If present, this method is executed automatically when the event "app.bootstrap" is triggered
|
||||||
|
|
||||||
Your plugin registration class can also inherit from Kanboard\Core\Base, that way you can access all classes and methods of Kanboard easily.
|
Your plugin registration class can also inherit from Kanboard\Core\Base, that way you can access all classes and methods of Kanboard easily.
|
||||||
|
|
||||||
@@ -85,9 +86,10 @@ Plugin Translations
|
|||||||
Plugin can be translated in the same way as the rest of the application. You must load the translations yourself when the session is created:
|
Plugin can be translated in the same way as the rest of the application. You must load the translations yourself when the session is created:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$this->on('app.bootstrap', function($container) {
|
public function onStartup()
|
||||||
Translator::load($container['language']->getCurrentLanguage(), __DIR__.'/Locale');
|
{
|
||||||
});
|
Translator::load($this->language->getCurrentLanguage(), __DIR__.'/Locale');
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The translations must be stored in the file `plugins/Myplugin/Locale/xx_XX/translations.php` (replace xx_XX by the language code fr_FR, en_US...).
|
The translations must be stored in the file `plugins/Myplugin/Locale/xx_XX/translations.php` (replace xx_XX by the language code fr_FR, en_US...).
|
||||||
|
|||||||
Reference in New Issue
Block a user