By: Rolando Payán Mosqueda, Drupal Developer at SeeD
In this article we will show you how to prepare an environment to start developing in Drupal 8 and take advantage of the power of an IDE.
First we will need to download Drupal 8, we go to the official site and select the latest version (currently beta6).
We unzip it on our web server and then install it.
Change all default values and configurations to develop or deploy our site.
Drupal 8 should be fast by default . Fast by default means for example page caching and CSS merging is enabled when you first install the site. Which is annoying for developers and theme designers. Therefore we should change these default values to make it easier for us when developing both back-end and front-end.
We must go to sites/ and copy the example.settings.local.php file to where we have the settings.php file and rename it to settings.local.php as shown in the following image:
Now we edit the settings.php file and uncomment the following lines:
Debugging Twig templates
We must edit the service.yml file which is located in the same settings.php folder and look for the twig.config section
as shown below:
And then we clear the cache using Drush: drush cr
Use a lightweight editor , or a full-featured IDE ? The eternal dilemma. To start developing in Drupal 8, it is highly recommended to use an IDE (Integrated Development Environment) that will help you create websites much faster and with little effort. There are several such as Eclipse, Aptana, Netbeans, Komodo, PhpStorm, etc. I personally prefer the latter, specifically version 8, for the features that I will explain below:
When you create a project it automatically detects our class autoload system and that due to its structure it is Drupal:
We configure it:
Setting up our code style
In PhpStorm we go to File → Settings and then in Editor →Code Style → PHP we select the Drupal code standard.
Symfony2 features specific to Drupal 8
Drupal 8 includes several Symfony2 components . There are some Drupal plugins that make development easier (hooks, drush, etc.). But PhpStorm has excellent support for the Symfony2 framework via the Symfony2 plugin (an Open Source plugin maintained by Daniel Espendiller ).
To take advantage of the tight integration between Drupal and Symfony2 for both module and core development, Daniel maintains an additional Drupal Symfony2 bridge plugin , which connects Symfony2 components to the Drupal infrastructure in terms of IDE understanding. There is also a PHP Annotations plugin to take advantage of advanced annotations support.
Installation:
First we need to install the plugins in PhpStorm. Go to File → Settings and under Plugins click on Browse repositories.
We write symfony2 as the keyword and install “ Symfony2 Plugin ”, “ Drupal Symfony2 Bridge” and “PHP Annotations”.
As soon as the plugins are installed, you need to enable the “Symfony2 Plugin” in your project, to do this go to File → Settings and go to Other Settings → Symfony2 Plugin and activate “Enable Plugin form” and then restart the IDE.
Specific parameters to fill in YAML files
Information about modules is now provided within module_name.info.yml files and PhpStorm thanks to the Symfony2 plugin provides us with the completion of the main Drupal-specific parameters in these files:
String completion in t() function
Strings suitable for use within the Drupal t() function are indexed throughout your project and offered for autocompletion:
Completion for routing (generating URLs) and navigation in YAML files
Relevant key values are populated in url() and other Drupal API functions to make it easier to look up the correct value:
You can also navigate to the file with Ctrl + Click (CMD + Click on Mac OS X):
Full support for service container
There are many useful features for service containers described in YAML files, including completion, Ctrl+Click / CMD+Click navigation, and more.
Support for the Twig templating engine
Twig is the new default template engine for Drupal 8 and PhpStorm with Symfony2 plugin comes with several features such as completion, navigation, Drupal function recognition and many more.
We can also detect when a function is obsolete to start replacing it with the recommended one, for example, it is shown with a line in the middle:
It means that soon this function will be removed from the core so we should start using the correct one, to do this we navigate to the function that is obsolete, with Ctrl + Click. Here we see when it will be removed and the function that will replace it, which we should start using.
These are some of the configurations that I use to work in Drupal 8, and that have become an essential part of my work. I hope you find them useful to get started.