Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
Plugin API
- Common - if none of types fit
- Payment - if you need to make payment for orders
- Language - if you need to make something related to localization
- Delivery - this one is still in development
- Legacy - this one is already deprecated
All types of plugins extend the capabilities of a Common type
Common
publish(string $channel, mixed $data = [])- publish a data to a channel (see pubsub)subscribe(string|array $channels, callable $handler)- subscribe a handler to a channel (see pubsub)setTemplateFolder(string $path)- set path for plugin twig templatesaddTwigExtension(string $extension)- add twig extensionaddSettingsField(array $params = [])- add plugin settings fieldaddScript(array|string $params = [])- add CUP custom JavaScriptaddToolbarItem(array|string $params = [])- add button on toolbaraddSidebarTab(array|string $params = [])- add button on toolbarenableNavigationItem($params = [])- add sidebar menu pointmap(array $params)- add new controller
Payment
getRedirectURL(Order $order)- should return a link to the payment page for redirect after placing an order
Language
addLocale(string $code, array $strings = [])- add new locale linesaddLocaleFromFile(string $code, string $path)- add new locale lines from fileaddLocaleEditor(string $code, array $translate)- add new to CUP editoraddLocaleTranslateLetters(string $code, array $translate)- if your language has characters that are not applicable in the URL, add their translation
Delivery (is still in development)
Legacy (is already deprecated)
setHandledRoute(...$name)- set names of the controllers processed in plugin in methodsbeforeandafter
Overridable functions:
before(Request $request, string $routeName)- function will be executed BEFORE processing the selected group of routesafter(Request $request, string $routeName, string $routeName)- function will be executed AFTER processing the selected group of routes
/src/Domain/AbstractPlugin.php
/src/Domain/Plugin/AbstractPaymentPlugin.php
/src/Domain/Plugin/AbstractLanguagePlugin.php
/src/Domain/Plugin/AbstractDeliveryPlugin.php
/src/Domain/Plugin/AbstractLegacyPlugin.php
Step 1: Create a folder in the plugins section, for example: Example.
Step 2: Create main plugin class with name by mask [your-plugin-name]Plugin, in our example: ExamplePlugin.
With contents:
<?phpdeclare(strict_types=1);
namespacePlugin\Example;
useApp\Domain\AbstractPlugin;
class ExamplePlugin extends AbstractPlugin
{
//...
}Step 3: In class define consts:
constNAME = 'ExamplePlugin ';
constTITLE = 'Example';
constDESCRIPTION = 'My first awesome plugin'; // (optional)constAUTHOR = 'Your Name';
constAUTHOR_EMAIL = 'Your E-Mail'; // (optional)constAUTHOR_SITE = 'Your site'; // (optional)constVERSION = '1.0'; // (optional)Step 4: Define constructor
publicfunction__construct(ContainerInterface$container)
{
parent::__construct($container);
$this->addSettingsField([
'label' => $this->parameter('ExamplePlugin_test', 'Test value'),
'description' => 'Set value',
'type' => 'text',
'name' => 'test',
'args' => [
'disabled' => false,
'readonly' => false,
'value' => null,
'force-value' => null,
'placeholder' => '',
'options' => [],
'selected' => null,
'checked' => null,
],
'message' => 'This is message',
'prefix' => 'pre',
'postfix' => 'post',
]);
$this
->map([
'methods' => ['get'],
'pattern' => '/api/test',
'handler' => function (Request$req, Response$res) use ($container) {
return$res->withJson(['text' => 'Hello world!']);
},
])
->setName('api:example:test');
// other init login here
}Step 5: Enable plugin
Open installed.php file and put line:
// example plugin$plugins->register(new \Plugin\Example\ExamplePlugin($container));Information
Usage
For developers