Quantcast
Channel: Riff Blog - Surfing the dataverse, to the sound of music
Viewing all articles
Browse latest Browse all 79

I hit ⌘D⌘R, you won't believe what happened next!

$
0
0
I hit ⌘D⌘R, you won't believe what happened next!Frederic MarandSun, 2016-12-04 18:59
OK, so you know the contents has almost nothing to do with the pseudo-clickbait-y title, right ? Well, actually it has: this is about the single most useful command in Drupal development. Guess which ?

Keep calm and flush cache

If you've done any Drupal development in the last ten years or so, you have probably noticed that the single most often used command in your work process is clearing the cache, be it in the Drupal UI at admin/config/development/performance (or its earlier incarnations), or hopefully with drush cr in Drupal 8 or drush cc all in earlier versions.

The thing is, while you probably switched from the web UI to Drush years ago, it's still a minor annoyance to have switch to a terminal, press the ▲ / ↵ combo and switch back to PhpStorm. Or switch view from the editor to the Terminal view. Isn't there a better way ?

You bet there is: as soon as I asked myself I knew it had to be easy, so let's see how it's done in PhpStorm in three steps:

  1. create an external tool
  2. map a key to it
  3. trick: there's no third step, it's already done

drush cr in PhpStorm 2016.3

Here is in detailed form how to implement the two steps above. Note that these instructions assume that (a) you are working in a Drupal 8 project opened one level above the Drupal docroot, as is typical in Composer-built projects, (b) Drush is local to the project, as it probably should. Adjust according to your actual situation.

ChoiceValueNotes
Open tool dialog
  • macOS: PhpStorm / Preferences / Tools / External Tools / "+"
  • Linux: File / Settings / Tools / External Tools / "+"
NameDrush CROr whatever...
DescriptionKeep calm and flush cache!...fits your fancy
GroupExternal toolsAlthough the widget looks like a selector, you needn't stick to existing groups, but may create one just by typing its label.
Synchronize files after executionCheckedIf you haven't excluded sites/default/files you may be interested in the changes wrought by the command. Otherwise, keep unchecked to reduce IDE work.
Open consoleCheckedYou normally want to see if something happens during the flush. Don't worry: only one console gets used for all calls to the tool.
Show inAs you preferProbably at least in editor views
Program$ProjectFileDir$/vendor/bin/drushAssuming you are working on a Composer-built project
ParameterscrOr cc all for D7 projects. Yes, you can use Composer for these too.
Working directory$ProjectFileDir$Especially important for projects built on drupal-composer/drupal-project where Drupal is not the project root: you want to run Drush from the Drupal root.
Open keymap dialog
  • macOS: PhpStorm / Preferences / Keymap
  • Linux: File / Settings / Keymap
Search for your toolDrush CROr whatever you typed in the Name field above
Map a keyYour choice: I used ⌘D⌘RNow you know what happened when I hit ⌘D⌘R

Viewing all articles
Browse latest Browse all 79

Trending Articles