You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will scaffold out everything you need to get started as a [private addon](#private-addons) within your site's `addons` directory.
20
20
21
-
Eventually, an addon will be available on Packagist and installable through Composer (and therefore live inside your `vendor` directory). During development however, you can keep it on your local filesystem as a path repository.
21
+
Eventually, an addon may be available on Packagist and installable through Composer (and therefore live inside your `vendor` directory). During development however, you can keep it on your local filesystem as a path repository.
22
22
23
23
:::tip
24
24
If you don't plan on distributing your addon or sharing it between multiple projects, you can take a simpler approach and just [add things to your Laravel application](/extending).
25
25
:::
26
26
27
+
28
+
### What's in an addon?
29
+
27
30
An addon consists of at least a `composer.json` and a service provider. Your directory may be placed anywhere, but for the sake of this example, we'll put it in `addons/acme/example`
28
31
29
32
```files theme:serendipity-light
@@ -42,6 +45,13 @@ resources
42
45
composer.json
43
46
```
44
47
48
+
### Composer.json
49
+
50
+
The composer.json is used by (you guessed it) Composer in order to install your package.
51
+
52
+
The `extra.statamic` section is used by Statamic to know that it's an addon and not just a standard Composer package.
53
+
The `extra.laravel.providers` section what Laravel uses to load your service provider.
54
+
45
55
```json
46
56
{
47
57
"name": "acme/example",
@@ -73,6 +83,10 @@ composer.json
73
83
}
74
84
```
75
85
86
+
### Service Provider
87
+
88
+
The service provider is where all the various components of your addon get wired together.
89
+
76
90
You should make sure that your service provider extends Statamic's `Statamic\Providers\AddonServiceProvider`, and not `Illuminate\Support\ServiceProvider`. Statamic's `AddonServiceProvider` includes some bootstrapping and autoloading that isn't included with Laravel's service provider.
77
91
78
92
```php
@@ -93,7 +107,11 @@ The `bootAddon` method should be used instead of `boot`. They are the same excep
93
107
makes sure to boot _after_ Statamic has booted.
94
108
:::
95
109
96
-
In your project root's `composer.json`, add your package to the `require` and `repositories` sections, like so:
110
+
### Installing your freshly created addon
111
+
112
+
If you ran the `make:addon` command, this would have been taken care of for you.
113
+
114
+
Otherwise, in your project root's `composer.json`, add your package to the `require` and `repositories` sections, like so:
97
115
98
116
```json
99
117
{
@@ -128,7 +146,7 @@ Your addon is now installed. You should be able to go to `/cp/addons` and see it
128
146
129
147
### Public addons
130
148
131
-
A public addon is one available as a composer package on packagist.org. Simple require it with composer:
149
+
A public addon is one available as a composer package on packagist.org. Simply require it with composer:
132
150
133
151
``` shell
134
152
composer require vendor/package
@@ -227,7 +245,7 @@ protected $commands = [
227
245
### CSS and Javascript
228
246
The method of adding assets will differ slightly depending on whether you are using Vite or another build process. We recommend Vite.
229
247
230
-
#### Using Vite
248
+
#### Using Vite (recommended) {#using-vite}
231
249
232
250
In your service provider, you may register your Vite config like this, adjusting the paths appropriately.
233
251
@@ -604,7 +622,7 @@ An example use case is a custom fieldtype maintained by a third party vendor. Ev
604
622
605
623
### Starters Kits
606
624
607
-
- Starter kits are installed via `php please starter-kit:install`
625
+
- Starter kits are installed via `statamic new` or `php please starter-kit:install`
608
626
- Starter kits install pre-configured files and settings into your site
609
627
- Starter kits do not live as updatable packages within your apps
610
628
- Starter kit licenses are not tied to a specific site, and expire after a successful install
Copy file name to clipboardExpand all lines: content/collections/sections/extending.md
+6-5
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,16 @@ section: extending_docs
8
8
---
9
9
## To addon, or not to addon?
10
10
11
-
In Statamic v2, practically every customization would need to be contained within an addon, even if you had no intention of distributing it.
11
+
Since Statamic is a Laravel package, you are in control over your application code.
12
12
13
-
Since Statamic v3 is a Laravel package, you are in control over your application code. You're free to add whatever extra code you like.
14
-
15
-
This makes the distinction much clearer: **If you want to reuse, distribute, or sell your features; you should make an addon.** Otherwise, you can just add things to your Laravel application.
13
+
**If you want to reuse, distribute, or sell your features; you should make an addon.** Otherwise, you can just add things to your Laravel application.
16
14
17
15
## How to extend Statamic
18
16
19
-
Some features can simply be placed in the right spot and they'll be wired up automatically. For example, placing a [tag](/extending/tags) class inside `app/Tags` will make it available to your templates without any extra wiring.
17
+
Many features can simply be placed in the right spot and they'll be wired up automatically.
18
+
19
+
For example, placing a [Tag](/extending/tags) class inside `app/Tags` will make it available to your templates without any extra wiring.
20
+
Or if you're building an addon, putting it in `src/Tags` will do the same.
20
21
21
22
Others could require some wiring, which would typically go in a service provider.
0 commit comments