Drupal 8 is coming and we're getting ready!
16 Sep 2015
Drupal 8 is soon to be released. So I decided to play with it and share my first impressions and findings.
Out of the box it looks very neat and robust. As opposed to its predecessors it comes with a bunch of modules in core. Views, i18n, transliterations, uuid, strongarm, features, breakpoints ckeditor to name a few all made it into core. Good news, less time spent on module installs. On the list of modules page there is also a search box saving you time on finding that one module among a huge list of others.
Overall Drupal 8 has kept its recognisable Drupal visuals and administrative navigation stayed very similar to Drupal 7. Which is a good thing.
If you are a developer then there is a surprise in the box for you. Better coding practices, object oriented approach, re-usability. Here is a short list of my findings and some things to consider.
1. Make sure you have right system requirements
For those of you running CentOS 6 it comes with Apache 2.2 however Drupal 8 requires minimum Apache 2.4. In this case you will need to either upgrade CentOS Apache or switch to Ubuntu 14.04 which comes with Apache 2.4 installed. To operate with Drush you will need to install version 8 or checkout dev version. Remove whatever default Drush you have or install both versions side by side. Installing via composer seems to be pretty straight forward. Another thing to notice with Drush is that there is no more Drush cache-clear all. Instead there is Drush cache-rebuild (cr). Drush disable module was deprecated in favour of Drush pm-uninstall module.
2. Write your own module
As a developer the first thing to do is of course to write your own module. Modules have a new home. All Drupal's core modules live in core/modules directory and contributed or custom modules make their habitat in modules folder at the root of Drupal install. If you have a installation and want to separate modules per site you can still do it the old way and place your modules in site/default/modules folder. You will notice that usual module.info file has now become module.info.yml and is written in YML language which makes things a bit more standardized. Now hook_menu is done away with and you can now define your paths in module.routing.yml file. Each route now has its own machine name by which it can be referenced. Menu's page callback is defined as 2 route's parameters: _controller and _content. Controller is a class that provides a method that renders themed output of the route. _content is the name of the method within this controller. Route can not only point to a method within controller but can also execute a service. Service is something new to Drupal and is borrowed from Symphony system. Services are further explained below. Though Drupal's hook system is still in place there is a great addition in Drupal 8 and this is the Plug In system. With the plugin mechanism your code can be completely object oriented and as such fully reusable. It pays taking time to learn about plugins and its discoverability. Youtube is a good place to start.
3. Write your own plugin
We all write code to create custom blocks. Well now there is a plugin to do just that. Plugin is just a PHP class that implements already preconfigured Drupal's plugin interface. In case of blocks this would be BlockPluginInterface. There are also ready to use plugin base classes. For blocks this is BlockBase class which in turn implements BlockPluginInterface. This class has all the method necessary to create a block. Go ahead and browse through the class to see what interesting things you can do with blocks out of the box and if it is not enough use the magic of object orientation and extend it by writing your own methods. Try it out and write your own block plugin. See for yourself how simple and straight forward it is. I bet you will get 'hooked'.
4. Dependency injections
As developers we are constantly bombarded by a very technical terminology like 'dependency injection'. Though it sounds very complicated in fact it is very simple and refers to passing an instantiated class as a parameter to another class. So instead of hardcoding class instantiation in a class you can pass it as a parameter or in another words 'inject' it into your main class. Dependency injection gives main class flexibility of processing different types of classes.
Services are all about dependency injection. In fact services serve as a wrapper to a class that has specific classes passed to it as parameters. Let's say you have 2 instances of class A. In the first instance it is injected with class B and C and in the second instance it is passed classes D and F. You might be in a situation where you need to instantiate class A with different parameters a few times. Every time you want to do this you would need to repeat instantiation of the injected classes. With services it becomes much easier. Service is a name defined by you that points to the combination of the main and injectable classes. Every time you call a service by its name it will instantiate and inject correct classes into the main one for you. So in our example calling on service 'abc' would return an instance of an A class with B and C injected into it. In turn calling on service 'adf' would return an instance of an A class with injected D and F instances. Services can be defined in module.service.yml file where you define service name, main class the service points to and an array of arguments containing classes that should be injected into the main class.
Of course there are many more things than this in Drupal 8
Mastering them takes time and practice and this is what makes development exciting. The best way to learn Drupal 8 is to help with resolving a huge list of issues on Drupal.org. Check it out, read comments, have a look at submitted patches and eventually write your own. After all this is what open source is all about.
Way to go Drupal 8.
Get in touch about your project
Give us a call or send us an email to talk through your project
We went to DrupalCamp London 2016
18 Mar 2016 Every year the Drupal community meet up at various conferences and more localised camps. This weekend we attended one of the largest camps in the country.
12 SEO top tips for better ranking with Drupal
1 Jun 2016 SEO. Search engine optimisation. Where to begin with the elusive task of search engine optimisation, around which an entire industry has formed?
More recent articles
Could mismatched web solutions scupper your business growth?
5 Aug 2020 If you’re responsible for the IT or strategic marketing in a medium or large business, ask yourself 'How is your web portfolio looking?'
5 ways your addiction to spreadsheets increases risk in your business
13 Jul 2020 It's time to talk about the elephant in the room: your addiction to spreadsheets! Relying on spreadsheets is bad for business. Here's how to fix that problem.