Skip to main content

Plugins

A Plugin (typically a laravel package) is a feature that can be active/inactive, and can be installed via composer. Plugins can have its own settings, a description, and will be displayed on the plugins page.

Important notes

Laravelpackage.com provides good documentation for the development of a Laravel package.

Composer package

You should make your plugin be installable via composer. You can achieve this by adding a gitlab-ci.yaml to your module. Gitlab will automatically register your package whenever you push a tag. For example:

stages:
- deploy

variables:
TAG: '0.0.1'

deploy:
stage: deploy
only:
- tags
script:
- 'apt-get update; apt-get -y install curl'
- 'curl --header "Job-Token: $CI_JOB_TOKEN" --data tag=$TAG "${CI_API_V4_URL}/projects/$CI_PROJECT_ID/packages/composer"'
info

You can find more information here: Installing Modules & Plugins.

Now when you push your changes, Gitlab will register your plugin as a composer package. For example: https://gitlab.qlic.nl/qore/plugins/postcode/-/packages

info

There is an existing dev plugin which can be used as an example: https://gitlab.qlic.nl/qore/plugins/postcode.

There is also an example module which registers Vue templates: https://gitlab.qlic.nl/qore/modules/qore-issue-tracker.

Updating documentation and release notes

After you have created a plugin, please take some time to add a page to https://qore.qlic.nl. You can do this by updating this project: https://gitlab.qlic.nl/qore/docs:

  • Update the config/extensions.php
  • Add a note to resources/views/notes/plugins/<your-plugin.md>

Getting started

Registering your plugin

You can register your own plugin in your service provider:

class NewPluginServiceProvider extends ServiceProvider
{
public function boot()
{
app(Plugins::class)->register(new NewPlugin);
}
}

Your plugin should extend QorePlugin. Here is an example:

class TestPlugin extends QorePlugin
{
public function boot()
{
app(Resources::class)->register(new testResource);
}

public function composerName(): string
{
return 'qore/test';
}

public function title(): string
{
return 'Test';
}

public function description(): string
{
return 'Dit is een test plugin.';
}
}
info

Each plugin that is registered, will be booted in the Skeletons' PluginServiceProvider.

Settings in plugins

Commonly, you will need the user to configure some settings in order to use your plugin.

You can achieve this by adding 3 methods:

    public function settingsUrl(): ?string
{
return 'test-plugin';
}

public function settingFields(): ?FieldCollection
{
return new FieldCollection(
Text::make(__('Test'), 'test')
->setMaxWidth('md')
->rules('required', 'min:3', 'max:60')
->hint('hier kun je een api key mee geven')
);
}

public function settingFieldsLayout(): ?FieldLayout
{
return (new FieldLayout())
->column('test')
}

public function storeSettings(array $data)
{
auth()->user()->tenant->setSetting($this->composerName(), 'test', $data['test']);
}

Prevent disabling

You can prevent users from deactivating your plugin by adding the following method:

/**
* This Plugin can not be deactivated by the user
*
* @return bool
*/
public function canBeDisabled(): bool
{
return false;
}

Plugin hooks

Every Qore extension (plugin/module) will have the following hooks that you can override:

    /**
* Boot is called on every request (while this extension is enabled)
* You might want to register resources here for example
*/
public function boot()
{
}

/**
* Optional: if this extension gets enabled
* For example, you might run a permission seeder here
*/
public function onEnable(): void
{
}

/**
* Optional: if this extension gets disabled
* For example, you might remove permissions here
*/
public function onDisable(): void
{
}

Helper methods

Back-end

You can get all plugins:

plugins()

You may retrieve a specific plugin:

plugin('qore/test')

Check if a plugin is active:

plugin_is_active('qore/test')

Front-end

You can retrieve all plugins in Vue templates

this.$plugins

You may retrieve a specific plugin:

this.$plugin('qore/test')

Check if a plugin is active:

this.$isPluginActive('qore/test')

For example:


<IssueTracker v-if="$isPluginActive('qore/test')"/>