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:
- create an external tool
- map a key to it
- 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.
|Open tool dialog
Keep calm and flush cache!
|...fits your fancy
|Although 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 execution
|If 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.
|You normally want to see if something happens during the flush. Don't worry: only one console gets used for all calls to the tool.
|As you prefer
|Probably at least in editor views
|Assuming you are working on a Composer-built project
cc all for D7 projects. Yes, you can
use Composer for these too.
|Especially important for projects built on
where Drupal is not the project root: you want to run Drush from the Drupal root.
|Open keymap dialog
|Search for your tool
|Or whatever you typed in the
Name field above
|Map a key
|Your choice: I used
|Now you know what happened when I hit