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.

Si Hobbs's picture
Si Hobbs
Fri, 11/23/2018 - 06:03

It was such a massive architectural shift. I've noticed only this year that a lot of the base APIs have stabilised. Problems are now solvable with StackExchange. And a lot of the key solutions are in place. Making a shift to heavy OO coding with dependency injection has been hard for me, but I'm better for it.

Ted's picture
Ted
Wed, 02/13/2019 - 02:54

I have noticed that in the "beginning", computers were used to make like easier. And it was. Frameworks, languages, APIs, etc, were much easier to master, learn and otherwise. But as time went along, somehow people figured, why make things easy when we can complicate things. I feel this is where Drupal 8 comes in (along with a few other technological "advancement").

I have some PHP background, REST, C++, Java, JavaScript, Vue, WordPress theming along with 13+ years in web dev. But man, Drupal 8 modules... I just can't wrap my head around this and keep thinking... WHY!? Why on earth anyone would create a mess out of a content management concept and sell it under the Drupal name?

I am on my 3rd week of learning Drupal 9 dev and so far I had nothing but frustration. Every time I try to learn a concept, I not only feel that I've been reading something that assumes at least 5 years of previous Drupal experience, but also I feel like it was written by people who have never produced training materials before and talking to people who already know all this.

In addition, everything refers to something else. Such as, in order to know A, you have to know B. But in order to know B, you need to know C first. But C requires E, and E requires a background in F, and so on, until I am ready to shut to book and stop all video courses because I feel like I wasted so much time already without understanding what the hell is it that was doing so far.

Madness. Complete madness.

I feel like Drupal was created by people who have no concept about simplicity. (...no offense... can you tell I'm frustrated?...)

Ted's picture
Ted
Wed, 02/13/2019 - 02:56

Sorry, I meant to say "I'm on my 3rd week of learning Drupal 8" - not 9 :-)

Add new comment