Aren't you a cutie?
Here at Chromatic HQ, the team is encouraged to give back to the open-source community. (And on company time!) One way to do this is by reviewing and contributing Drupal patches. For me, this can be both rewarding and frustrating. When things go well, I feel good about contributing and I might even get a commit credit! But there are times when patches don't apply, I have no clue what's wrong and I need to start fresh. First, I curse mightily at the time wasted, then I create a new db, and then re-install a fresh copy of Drupal, and then configure it etc. etc. Using drush site-install
makes this process relatively easy, but what if it could be easier? (Hint: It is!)
Hooray for promiscuity!
I recently had a fling with Drush's core-quick-drupal
command. I had known about it for years, but I hadn't realized what it could really do for me. This has now changed, and together we're having an open affair!
For the uninitiated, drush core-quick-drupal
takes advantage of PHP's built-in web server (PHP >= 5.4) and uses a sqlite database to get a fresh, stand-alone copy of Drupal up and running, all in about a minute. It has two aliases: drush qd
and, my personal preference, drush cutie
.
Out-of-the-box overview
- In about a minute it installs a full instance of Drupal.
- Runs a web server at
http://127.0.0.1:8888
(no apache config). - Uses a self-contained sqlite file as the db (no mysql db to create and configure).
It's so much fun, you may want to follow along. From the command line, just cd
to a folder of your choosing and run drush cutie --yes
. (You'll need to have drush
installed.)
Behind the scenes, a folder is created called quick-drupal
with a timestamp appended to the end. (One of my older cutie
folders is quick-drupal-20160214193640
... a timestamp from a Valentine's evening with Drush that my wife won't soon forget!) Inside the new quick-drupal
folder are subfolders with the latest D8 files and the sqlite db file. (There are lots of options to customize the Drupal version and environment, but the default nowadays is Drupal 8.)
Running it looks something like this
drush cutie --yes
Project drupal (8.0.3) downloaded to
...
Installation complete. User name: admin User password: EawsYkGg4Y
Congratulations, you installed Drupal!
Listening on http://127.0.0.1:8888
(The output above has been edited to highlight the tastier bits!)
And with that I have the latest version of D8 running at http://127.0.0.1:8888
. As you can see from the shell output above, the superuser is admin with a password of EawsYkGg4Y.
Okay, okay, very cool, but what can I do with it?
Here's a breakdown:
- Review patches with minimal fuss, thereby giving back to the Drupal community.
- Investigate new modules without sullying your main dev environment.
- Test that new Feature you created to see if it really works.
- NOT RECOMMENDED! When that friend asks you how long it will take to build him a website, respond with "about a minute" and fire it up.
You thought I was done?
Let's run through the steps to review a patch. This is where drush core-quick-drupal
really shines because it's best to have a clean install of Drupal to work with; this minimizes the number of externalities that can interfere with testing. Having a single-command, throwaway copy of vanilla Drupal is the way to go.
You could call this a blog version of a live demo; I have chosen a patch out in the wild to review. I found this one for the core taxonomy module, that had a status of "Needs Review" on D.O.
The patch file itself is here: https://www.drupal.org/files/issues/taxonomy-term-twig-cs.patch
Here are the steps I took on the command line:
# Install a temporary copy of D8 into a folder I named "test2644718"
drush cutie test2644718 --yes
With the above command I got my environment running. The patch itself simply fixes the formatting in taxonomy-term.html.twig
, which is a default template file for taxonomy terms, provided by the core taxonomy module.
I first tested to see the original template in action. Satisfied with the way it was working, I took steps to apply the patch.
# Move into the root folder of the new site
cd test2644718/drupal/
# Use wget to grab the patch from D.O.
wget https://www.drupal.org/files/issues/taxonomy-term-twig-cs.patch
# Apply the patch
patch -p1 < taxonomy-term-twig-cs.patch
patching file core/modules/taxonomy/templates/taxonomy-term.html.twig
The patch was applied successfully and a minor change in taxonomy-term.html.twig
was made. I quickly tested to ensure nothing had blown up and was satisfied that the patch works as expected.
Back in D.O., I added my two cents and marked the issue as Reviewed & tested by the community. And that's that.
Update
Though the patch originally sat awaiting review for 2 months, I'm happy to claim that my review got things moving again! After I posted RTBC, a flurry of activity took place with the scope increasing and new patches being created. I reviewed those too! A day later the patches were committed to 8.1.x. Nice.