Building Statamic addons: what I've learned shipping a handful of them
On this page
I have published a handful of Statamic addons. Most are small fieldtypes that exist because a client needed one thing core did not do and bending core would have been worse. One is a paid product. Here is what each one is and what building them taught me.
The addons
- Image hotspots: pick points on an image and attach fields to each. Built for an annotated product shot.
- Rive: upload a
.rivfile, preview the animation in the control panel, configure it, play it on the front end. - Stripe form field: take a card payment inside a normal form submission.
- 3D field: upload a model and render it with
model-viewer, with a tag for the front end. - Calendar links: an event fieldtype that outputs Google, Apple, Outlook and Yahoo links, on top of
spatie/calendar-links. - Feedback widget: drop my feedback tool's floating button onto a Statamic site with a config screen. No fieldtype at all, just a tag and a settings page, which is the other common addon shape.
- Email subscriptions: lists, subscribers, sendouts built from entries. The paid one.
Fieldtypes are the sweet spot
A fieldtype is a Vue component for the control panel plus an Antlers tag or augmentation on the front. Keep the saved value small and JSON-shaped: an asset path and a few numbers, not a rendered blob. An image reference and a list of points, or a file path and a few viewer options, is enough. The editor's experience lives in the component, the site's experience lives in the tag, and the content file stays readable in git.
The Statamic 6 build that actually works
The default Vite setup produces an ES module that bundles its own Vue. In the control panel that means a second Vue instance, and your component cannot see the CP's. Every one of my fieldtype addons now uses the same vite.config.js: build an IIFE, mark vue external and map it to window.Vue, import the CSS from the single JS entry, and a banner that restores the Fieldtype mixin:
banner: 'if (window.__STATAMIC__) { window.Fieldtype = window.__STATAMIC__.core.FieldtypeMixin; }',
Statamic 6 moved that mixin, dropped Vuex, and changed the shape of asset field meta from a handle string to an object. Each of those broke an addon of mine on upgrade day.
Blade views in the Statamic 6 control panel
For the subscriptions addon I kept the control panel in Blade so one codebase works on v5 and v6. The catch in v6: the CP reads your view's innerHTML and recompiles it as a Vue template, so the element on screen is not the one the server sent. A DOMContentLoaded listener binds to a discarded node and never fires, and the form falls back to a native POST. Delegate every handler from document and it survives the recompile. That cost me two patch releases before I read the CP bundle.
Permissions
If your addon adds a collection, taxonomy, global or form, add the permissions to the editor role too. New sections are invisible to non-super users by default. The client's editor is the one who finds out.
Testing
Statamic feature tests read and write the real content and storage/forms directories. A tearDown that cleaned up "test" submissions once deleted 86 real ones. Point the Stache stores at a fixtures path in your TestCase, or use PreventsSavingStacheItemsToDisk for addons. There is a whole post on that: Statamic feature tests write to your real content folder.
Publishing
A Composer package with an extra.statamic block, semver tags, Packagist, and docs in the README with screenshots, because the README is the product page. The small fieldtypes are free; they are small and I want people to use them. The subscriptions addon is paid, one project per license, a flat one-time fee. It replaces a monthly email service for a small site, it is by far the biggest of the set, and a one-time price is the one I would want to pay.
The honest downside
Every control panel internal you touch is something a core update can move. Keep the surface area small, prefer the public fieldtype and tag APIs, and budget a day per major Statamic release to find out what moved.