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.

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

 
This entry was posted in Cool Feature, PhpStorm and tagged , , . Bookmark the permalink.

13 Responses to New in 4.0: Drupal coding style support

  1. Now that’s making an effort. Nice one. :)

  2. Boris Hinzer says:

    Maybe I’m repeating this, but I still got no comment on your former blogpost, but what about TypoScript support for TYPO3 ? http://youtrack.jetbrains.com/issue/WI-7249

  3. Ingo Renner says:

    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.

    cheers!

  4. Pol says:

    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:

    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')
    ->fields('b')
    ->condition($or)
    ->condition('theme', $theme)
    ->execute();

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

  6. Ksaveras says:

    Please add Symfony2 style support.

Comments are closed.