Features Releases

Joomla! support in PhpStorm

Recent versions of PhpStorm have come with increasingly improving support for the popular CMS Joomla! Here we take a look at some of the useful features from recent versions.

Joomla Logo

Joomla! is a long-running and popular PHP content management system, and PhpStorm has some custom features added in recent versions to help developers working with Joomla!

The first thing you’ll notice when opening a Joomla! project in PhpStorm is that PhpStorm detects the fact you’re working with a Joomla! application, and asks you if you’d like to enable Joomla! support.

Joomla Detected

When we click on Enable, PhpStorm will ask us to browse to the location where the Joomla! codebase is installed. In my case it was the root of the project I’m working on. It’s also worth clicking on the second prompt that asks you if you want to detect the namespace roots; this saves us having to configure the paths for the project manually.

Once we’ve enabled the Joomla! support, PhpStorm then asks if we would like to enable the Joomla code styles and if we would like to enable the Joomla! docblock templates. Joomla! has its own rigorous code style and docblocks, so enabling these is always a good idea.

At this point, it’s worth noting that I’m working on a plain install of Joomla! which has the demo catalogue data installed running on a MySQL database. At this point, I have only run through the installation wizard and deleted the `installation` folder once the wizard has run.

Joomla Installed

While the Joomla! code styles and docblocks are more obvious features of the Joomla! integrations, there are some more subtle tricks we can use to make our lives developing on Joomla! easier.

Database

PhpStorm comes with a database browser built right in, and the Joomla! integrations allow us to quickly and easily configure the database tool from the configuration file that Joomla! creates containing our credentials. Once we’ve opened the Database tool (I usually hover over the menu icon in the bottom left of the screen and select Database), we can add a new datasource for our Joomla! database by clicking the + icon to add a new datasource, and then selecting Import from sources…

We then see the Add New Datasource dialog, but with all the fields completed from the settings in the `configuration.php` file; it’s simply a case of clicking Test Connections to check everything is working, and then clicking OK.

Joomla Datasource

You can see that Joomla! adds a prefix to the database tables (which is generated or configured during the installation wizard), and this can make writing queries in the query editor (part of the database tool) quite painful. To make it easier for you, PhpStorm provides database prefixes support and automatically changes #__  to the prefix that is defined in the $dbprefix field in the configuration.php file.

JHtml::_($argument), JText::_($argument) support

The latest versions of PhpStorm come with support for the `_` static method of the JHtml class. This is a magic method that allows you to invoke helpers by passing in a string that contains the class name plus the method name, separated by a dot. PhpStorm can parse these strings, and provide you with the usual helpers associated with class and method names in the IDE. For example, here we are using the `form.token` helper, and when we invoke Brief Info  over the string (default to CMD/CTRL plus hover over the item), we see the method signature for this helper method:

CMD/CTRL and clicking the string takes us straight to the `token` static method of the `JHtmlForm` class just as we would expect. Of course, the `JHtml` class comes with full code completion and type hinting like all classes do in PhpStorm.

The same way it works for `JText::_($argument)`, `JText::script()`,  and`JText::sprintf()`.

Check the full version of our tutorial on Joomla! Development using PhpStorm in our PhpStorm tutorial space.

Give Joomla! Plugin in the latest PhpStorm 2016.2 a try and let us hear your thoughts in the issue tracker, comments below or in our forums.

~ Gary and the PhpStorm Team

The Drive to Develop

image description