New in 4.0: Drupal coding style support


PhpStorm 4.0 contains a bundled predefined coding style for the popular Drupal content management platform. Currently just reformatting your code in PhpStorm removes 99% of errors reported by Drupal coder-review and makes your code fit to Drupal coding standards.

Setting It Up

You can either use your existing code style scheme or create another one. In both cases it works the same way: Drupal settings are applied to your currently selected scheme. After choosing Settings|Code Style|PHP, simply click to “Set from…” link at the right top corner and select Predefined Style|Drupal as shown below:

The settings which are not required (explicitly specified) by Drupal coding style are left unchanged.

Drupal-style Formatter in Action

Let’s take a small code fragment, for example:

After reformatting the code will be adjusted according to Drupal coding standards:

If you run Drupal coder-review afterwards, it will likely report few errors/warnings instead of hundreds which you normally would have with an arbitrary code not following Drupal coding standards. All the messages like “Use an indent of 2 spaces”, “Curly braces { should end a line” etc. will be gone.

It’s a nice feature to try in PhpStorm 4.0 EAP if you are coding for Drupal. Let us know what you think about it and submit your findings and improvement suggestions in YouTrack.

Comments below can no longer be edited.

13 Responses to New in 4.0: Drupal coding style support

  1. Michael Ussher says:

    March 15, 2012

    Now that’s making an effort. Nice one. ūüôā

  2. Boris Hinzer says:

    March 15, 2012

    Maybe I’m repeating this, but I still got no comment on your former blogpost, but what about TypoScript support for TYPO3 ?

  3. Ingo Renner says:

    March 15, 2012

    Boris, I don’t think this is something we should ask the kind folks of JetBrains for. I’d like to see TYPO3 coding style support, too though. For TypoScript support I rather see the TYPO3 community as the ones who should provide that if PhpStorm can/does provide a suitable API for it… After all it’s a PHP IDE, not a TYPO3 IDE.


  4. Pol says:

    March 15, 2012

    Excellent, just excellent !
    I was writing a document to push PHPStorm at work, I think this is an excellent argument !

    Thank you !!!

  5. droplet says:

    March 15, 2012

    I caught few problems

    #1. try-catch
    catch should be on new line, eg
    try {
    $this->connection->queryRange("SELECT $column FROM {" . $table . "}", 0, 1);
    return TRUE;
    catch (Exception $e) {
    return FALSE;

    #2. Drupal preferred array item on own line

    $form['start'][$module] = array(
    '#type' => 'hidden',
    '#value' => $update['start'],

    #3. Not in Drupal standard but its preferred way

    $database_blocks = db_select('block', 'b')
    ->condition('theme', $theme)

    #4. after reformatting. some lines exceed 80 chars per line.

    • droplet says:

      March 15, 2012

      WP removed the indent spaces ūüôĀ

    • Ronald says:

      April 26, 2012

      There is still an 80 chars per line limit? Who still needs that? Monitors these days are getting wider and wider. Pfff.

  6. Ksaveras says:

    March 15, 2012

    Please add Symfony2 style support.