How To Make Waves

on March 22nd, 2019

Hey Bud, it's me again! The boys are in Germany and left me in charge. What should we talk aboot today? I'd bet my Canada Goose jacket that you hosers are itching to make something with v3, eh?

First off, we're improving the old generator commands. We heard 'less is more', so we just deleted half of them. Hey now, don't lose your Timbits! I didn't say they were gone! Here, need a serviette to wipe those tears? Sorry bud, that was my fault, here let me explain... Now that v3 is installed into a standard Laravel file structure, it's easier to use the built in artisan make generators for things like controllers, listeners, providers, commands, jobs, etc. From now on, we're focusing on Statamic-specific generators using the artisan statamic:make namespace:

php artisan statamic:make:tag Waves

And leaving the Laravel stuff to artisan make:

php artisan make:provider WavesServiceProvider

The Power of Politeness

We still want to be polite though eh, so we've aliased all of the Statamic-specific artisan commands into a Canadian-friendly please command, which you can read more about here.

php please make:tag Waves

Brings a tear to my eye, so polite! Anyway, I mention it because I'll be using please in the examples below. Wouldn't want to leave you in the cold. It's cold up here you know!

Less Wizards, More Magic

We've also ditched most of the CLI wizards in favour of a more artisan-like approach. By relying more on command line arguments and options instead of input prompts, you'll have more flexibility when it comes to making aliases, etc. Some of the wizards are still there, but are now completely optional. For example, if you run this command without arguments:

php please make:user

You'll get the standard user creation wizard. However, if you pass an email address argument:

php please make:user [email protected]

We'll non-interactively create a user for you to manually build up.


In v2, you could create Site Helpers:

`-- helpers
    |-- Tags.php
    |-- Modifiers.php
    `-- Filters.php

These files provided an easy place to house one-off tags, modifiers, and filters, but in turn made it a bit more difficult to extract these helpers to an addon, should you have decided to share it with the world.

In v3, we now generate a dedicated file for each individual helper within your app folder:

php please make:tag Waves
php please make:modifier Canadian
|-- Tags
|   `-- Waves.php
`-- Modifiers
    `-- Canadian.php

The structure of these folders and files is exactly what you'd expect to see within an addon's src folder, so it'll be easier than ever to port this stuff to the Marketplace, should you decide to leave the igloo!


Speaking of addons, they're now installed via Composer. Don't spill your poutine though! If composer is new to you, like milk-in-a-bag is to my American brethren, we've got your arse once again! Just run:

php please make:addon mckenzie/waves

And we'll link up and composer require everything for you so that you can get straight to building that addon:

If it were the 80's and Jack were Canadian, surely he'd say "Rad eh"!

Keep it local for as long as you'd like. If and when you're ready to share it with the world, extract your addon folder to a separate repo and publish on Packagist and the Marketplace!

No doubt you'll be able to make waves with the new generators! Anyway, I gotta take off and fill the wood stove 🍻

Jesse Leite
Jesse Leite, The Canadian Developer @ Statamic
The Canadian Developer

Copyright 2020 Statamic