fromJune 2014

Drush: The Swiss Army Knife for Drupal

Part Three: The Tweezers

I’m personally amazed at the new features and advances of Drupal 8. There are so many changes to talk about, but for this article I want to cover configuration management. In case you haven't yet heard, with the new version of Drupal we see all configuration stored in files instead of in the database. With the new version of Drush there are some built in tools to help manage these files.

At the time of this writing, the recommended version of Drush is 6; however, this article uses commands that were introduced with version 7. Before you can try any of these, you’ll need to be running that version of Drush. The tricky part is that it currently does not have a full release. Typically, you would not want to install a project’s dev release in a production environment. I’m going to assume you will be working locally, on a development server, or are confident you can’t hurt anything otherwise.

In a previous article I explained how to install Drush using Pear; however, the project is shifting to Composer. You can still install via Pear, or even manually, but it's recommended you switch to Composer. Drush has also been moved to GitHub; you will find additional instructions for installing with something other than composer there.

Assuming your environment already has Composer installed, get the latest release of Drush 7 and issue the below command.

composer global require drush/drush:dev-master --prefer-source

Next, verify that it installed:

drush version

The output should indicate you have Drush 7.0-dev, or something along those lines. If it didn't work you may need to log out and back in again before your SSH user will know it's installed.

Now that we have the latest and greatest, the next thing to do is get Drupal 8. Using Drush you can request a specific version of Drupal, or any project, by providing the version number. If you don’t provide a version it will find the recommended version and download that instead.

To get the dev version of Drupal, type this:

drush dl drupal-8.x-dev

Next, let’s get a site installed. Keep in mind that you will need to configure your web server and database since this command only handles the install of Drupal.

drush site-install --db-url=mysql://USER:PASSWORD@localhost/DATABASE

Upon completion, the username and password will output to your screen.

Checkpoint! Now we can explore the site’s configuration.

Drupal creates a folder with a long randomly-generated name inside the site’s files folder. Inside this folder it writes out every setting to a YAML file. The great thing about this is for those who want to run version control they can now track every change to Drupal's configuration. Previously this was not possible, since it was all inside the database.

Now that we have this folder, the maintainers of Drush have added a new set of commands to help us more easily find, view, and modify these files.

Let's play around with some site settings. Type in the command below to get the active configuration.

drush config-get

The output will show you the site’s name, e-mail, front page, error pages, etc. You will notice that the Site Name is set to something generic: that is a result of installing with Drush but not providing a name at the time of install. Let’s update the configuration file and provide a new name.

drush config-set name “Drush is the Best”

Now check your site. You will see the change reflected immediately.

Using the same command structure, you can modify any configuration: in the above command, “” is the configuration file, “name” is the key, and “Drush is the Best” is the value.
Using config-set works great when modifying a single value, but lets say you’d like to set the site’s name, e-mail, and front page. It would likely be easier to use the following:

drush config-edit

This will open the specified configuration file and allow you to modify the file in the terminal. Save it and the configuration changes are applied.

I’m also a fan of using the shortcuts: instead of typing out config-get and config-set, try using cget and cset instead.

One of the harder things to master is knowing where to find the particular configuration you are looking for. Fortunately there is a command to help us with that. Let's say you want to edit something related to user settings. Since you know it's a user setting, you can list all the user files by issuing this command:

drush config-list user

The output will list every file available in user settings, which allows you to find the file you wish and modify it quickly using config-set or config-edit.

If you're already running most things via Drush, it won’t take long to adapt these new commands. It's very likely you'll even prefer them over the alternatives. The key is to get out there and start using them until they become second nature.

If you're still new to Drush, take baby steps. You might also consider reading the Drush articles in previous issues: Part One: The Can Opener and Part Two: The Saw and the Blade

One last thing...

If you ask me, no great work is complete without an Easter Egg. The next Drush command you issue, add “--druplicon” to the end.

Image: ©


From our blog

Entity Storage, the Drupal 8 Way

In Drupal 7 the Field API introduced the concept of swappable field storage.

The Drupal 6 to 8 Upgrade Challenge - Part 2

Having concluded the readiness assessment, we turn next to migrating the content and configuration. In reality, there’s little chance that we would migrate anything but the blogs from our old site. For the sake of giving Migrate in Core a workout with real conditions, however, we’re going to upgrade with core’s Migrate Drupal module rather than rebuilding.

The Drupal 6 to 8 Upgrade Challenge - Part 1

Nathaniel Catchpole , the Drupal 8 release maintainer and Tag1 Senior Performance Engineer, suggested that Drupal shops everywhere could support the

DrupalCon Austin

The entertainment industry is not for the faint of heart.

Drupal Watchdog Joins the Linux New Media Family
Drupal Watchdog 6.01 is the first issue published by Linux New Media.

Drupal Watchdog 6.01 is the first issue published by Linux New Media. Come see the Drupal Watchdog team at DrupalCon 2016!

Drupal Watchdog was founded in 2011 by Tag1 Consulting as a resource for the Drupal community to share news and information. Now in its sixth year, Drupal Watchdog is ready to expand to meet the needs of this growing community.

Drupal Watchdog will now be published by Linux New Media, aptly described as the Pulse of Open Source.

Welcome to DrupalCon Barcelona - The Director's Cut

For all you schedule-challenged CEOs – and ADHD coders – this Abbreviated Official Director’s Cut is just what the doctor ordered.

Welcome to DrupalCon - The Barcelona Edition

Did we have fun in Barcelona?
OMG, yes!

Did we eat all the tapas on the menu and wash them down with pitchers of sangria?
Yes indeed!

Recursive Closures and How to Get Rid of Them

This came up while manipulating taxonomy children and their children recursively, so it’s as not far from Drupal as you’d think.