Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions content/collections/docs/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You can use Composer to install any addon:
composer require vendor/package
```

The command can be found on the addon's page in the Control Panel or the Statamic Marketplace.
The command can be found on the addon's page in the [Statamic Marketplace](https://statamic.com/addons).

:::tip
Some first party addons – such as the Static Site Generator or Eloquent Driver - have their own dedicated commands which will be noted on the same pages.
Expand Down Expand Up @@ -49,6 +49,4 @@ You can choose which edition is installed by entering it into your `config/stata
'addons' => [
'vendor/package' => 'pro', // e.g., 'jezzdk/statamic-google-maps' => 'pro'
]
```

Or, by choosing it from an addon's details view in the Control Panel.
```
1 change: 1 addition & 0 deletions content/collections/docs/git-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ You are free to define the tracked paths to be considered when staging and commi
'paths' => [
base_path('content'),
base_path('users'),
resource_path('addons'),
resource_path('blueprints'),
resource_path('fieldsets'),
resource_path('forms'),
Expand Down
60 changes: 60 additions & 0 deletions content/collections/extending-docs/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,66 @@ if ($addon->edition() === 'pro') {
You don't need to check whether a license is valid, Statamic does that automatically for you.
:::

## Settings

Laravel config files are great for storing application settings, but they're not ideal for settings you might want users to edit through the Control Panel.

You can register a settings blueprint in your addon to give users a friendly interface for managing settings. Drop a blueprint file in `resources/blueprints/settings.yaml` or register it in your service provider like this:

```php
public function bootAddon()
{
$this->registerSettingsBlueprint([
'tabs' => [
'main' => [
'sections' => [
[
'display' => __('API'),
'fields' => [
[
'handle' => 'api_key',
'field' => ['type' => 'text', 'display' => 'API Key', 'validate' => 'required'],
],
// ...
],
],
],
],
],
]);
}
```

Your addon's settings page will show up in the Control Panel under **Tools -> Addons**. Pretty convenient.

You can even reference config options (and by extension environment variables) in your settings blueprint using Antlers, like so: `{{ config:app:url }}`.

Settings are stored as YAML files in `resources/addons` by default, but can be moved to the database if you prefer. Just run the `php please install:eloquent-driver` command and you're all set.

You can retrieve the settings using the `Addon` facade:

```php
use Statamic\Facades\Addon;

$addon = Addon::get('vendor/package');

// Getting settings...
$addon->settings()->get('api_key');

$addon->settings()->all();
$addon->settings()->raw(); // Doesn't evaluate Antlers

// Setting values...
$addon->settings()->set('api_key', '{{ config:services:example:api_key }}');

$addon->settings()->set([
'website_name' => 'My Awesome Site',
'api_key' => '{{ config:services:example:api_key }}',
]);

// Saving...
$addon->settings()->save();
```

## Update Scripts

Expand Down
24 changes: 24 additions & 0 deletions content/collections/extending-docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ If you're creating an addon, you can quickly [register event listeners or subscr

## Available Events

### AddonSettingsSaved
`Statamic\Events\AddonSettingsSaved`

Dispatched after an addon's settings have been saved.

``` php
public function handle(AddonSettingsSaved $event)
{
$event->addonSettings;
}
```

### AddonSettingsSaving
`Statamic\Events\AddonSettingsSaving`

Dispatched before an addon's settings are saved. You can return `false` to prevent them from being saved.

``` php
public function handle(AddonSettingsSaving $event)
{
$event->addonSettings;
}
```

### AssetContainerBlueprintFound
`Statamic\Events\AssetContainerBlueprintFound`

Expand Down