My first thoughts on Drupal 8 development

So on my summer holiday I decided to finally take a look at custom module development for Drupal 8. During this time I made some interesting findings, and thought sharing them would probably help others too.

Note that I was determined to build a REST API module, so a lot of the findings below are regarding that aspect of development.

Documentation is really lacking in parts

It's kinda sad, but quite often I had trouble finding information on how to use different controllers or functions, or how to do stuff X in Drupal 8 compared to Drupal 7.

Googling is of course the way to go here, but sometimes the only "documentation" on how to do something was an issue queue where it was discussed how it should be implemented. 

And because of the Drupal 8's long development, I find some blog posts from around 2014 that were just plain wrong or changed in more recent years. 

One thing that I ran into multiple times is that in comments section people mentioned "you shouldn't use \Drupal", but they provided no alternatives or even reasoning why! 

Some things are easier, some harder

I think in general, compared to Drupal 7, development on Drupal 8 is a bit harder due to it's more complex base. This is alright, I guess, because of this complexity, we can have plenty of shortcuts to do other stuff and it's more compatible with other PHP frameworks, libraries and tools.

I tweeted the above tweet on a frustration, thanks to @NickWilde1990 for replying, I learned that you just do $node->field_something->value instead :) 

Modules are coming along nicely

Luckily a lot of modules are ready to be used in Drupal 8 and are in good shape! I was positively surprised of this. Only things that I would like is more finished location modules and fivestar-module (Voting API is for Drupal 8 though already).

Composer is awesome

Man, this really caught me off-guard. I needed to have GeoIP functionality in module. So I looked in packagist.org for a library and sure enough, I found geoip2/geoip2. In Drupal's root I ran "composer require geoip2/geoip2", and then in my code I just wrote "use GeoIp2\Database\Reader;" and IT JUST WORKS. That's pretty amazing. Good job for the people working on this! One small minus point comes from the fact I had to run in Drupal's root folder, I was using multisite and it wasn't clear how to enable just for that one website.

Cacheability is a HUGE thing

Caching in Drupal 8 has been probably the biggest hurdle for me. The default caching in Drupal 8 is pretty aggressive, which I understand. 

The documentation is really hard to comprehend, at least for me. It uses a ton of new concepts and terms I have not heard or used in Drupal 7 development before. After couple of days of studying, I finally think I have pretty good grasp on what is happening. And I have to say, the caching system is pretty darn sophisticated!

REST is bit of a mess

Like I said in the beginning of this post, I was set out to build a REST API. There's not a ton of documentation for this purpose, so I had to read a lot of code from the core modules and see what they are doing. 

I couldn't get POST requests to work for two days, but after trial and error I realized the problem had something to do serialization/normalization. I just wanted to build a simple JSON API (JSON in, JSON out), and this proved out to be bit of a problem. Drupal 8 seems to by default only accept entities as POST data, and I had to write a custom denormalizer for JSON (seriously?) I have a question about it on Drupal StackExchange, it has more details.

 

Comments

Chris Weber's picture
Chris Weber
Thu, 07/07/2016 - 17:49

While the syntax you object to seems strange and difficult it mirrors the Content repository syntax I've seen in a number of other systems, across different platforms, using different languages.

I like it because it's very readable. I get exactly what it's trying to access.

Edwin Smith's picture
Edwin Smith
Thu, 07/07/2016 - 17:52

I've also been working on a huge Drupal 8 project. Some additional thoughts:

- Drupal Console is indispensable for scaffolding basic modules. Like, seriously.
- Composer is awesome, and since Drupal is built on Symfony, sometimes you can find a tool you need even if Drupal doesn't have one in their own repo.
- Composer workflow is also poorly documented. As is configuration sync workflow.
- Event subscribers are a super cool idea, but entity events are woefully lacking.
- And yep, trying to work around the layers of caching can be quite frustrating. There's no simple on/off toggle in the settings any more.

Add new comment