7 Key Lessons I Learned Building Sites in Drupal 8

7 Key Lessons I Learned Building Sites in Drupal 8

Still feel like walking on quicksand at the thought of taking a Drupal 8 web project “by the horns”? Been there... many times! To boost your self-confidence as a Drupal developer aiming to turn into a Drupal 8 expert, I've put together a list of 7 most important lessons that I've learned across my experience of building sites in Drupal 8. Feel free to dig in, to filter them through to your liking and to turn the ones that you do find helpful into your jump start as you take the leap to Drupal 8:

Before I even go on with my top lessons learned as a Drupal 8 developer in Toronto, I feel like giving you my first valuable (at least I do consider it so) advice: "you need to change your ways of building sites in Drupal from ground-up!

Don't get tricked into thinking that since Drupal 7's and Drupal 8's UIs are so much alike your:

  • gained expertise in templating
  • the fact that you master the hook system, procedural PHP and theming quirks

… will be of no help to you!

When you say “building sites in Drupal 8” you instantly say:

  • mastering object-oriented development patterns 
     
  • being comfortable with Symfony and with other external dependencies that Drupal 8 now leverages in its core 
     
  • changing the old ways of building sites in Drupal 7 and adopting a whole new set of best practices (handling custom entities, nodes and blocks in Drupal 8 is a whole different story)
     
  • including tools like Drush, Drupal Console and Composer into your own “arsenal” as a Drupal developer

In short: much has changed, at a detail level, in Drupal 8! We can easily talk about a completely different platform, with completely different core components, requiring a whole new... Drupal developer mindset!

And now, the lessons I promised you:
 

1. Reusable Components: Less Development Time, Loads of Convenience 

And it's around the wireframing phase of your project that you should set up a plan for reusing those web components that appear in multiple locations of the site.

Invest time in identifying the patterns that repeat or which are similar across different sections of your future website and come up with a way to reuse them. 

Then, with such a well-thought-out solution for creating reusable components at hand you'll be:

  • building sites in Drupal 8 a whole lot faster, you'll be simplifying your whole workflow
  • implicitly reduce production costs (and guess who'll be thrilled to hear that!)
  • manage to maintain consistency throughout the site 

Moreover, the administrators and all those “in charge” with content will tank you, since creating it (content) will turn into a lot more streamlined process!

Needless to add that reusing components across the website instantly leads to less duplication and, therefore, to a lighter database, too!

Note: I would advise you to take the Paragraphs module out for a “drive test”! You'll be amazed of how much flexibility it will provide in terms of content versioning.
 

2. Growing Comfortable With OOP and The Plugin Structure: A Must!

It's time you “shook off” your old ways of building websites in Drupal! The hook()system and the procedural PHP are replaced, in Drupal 8, with an object-oriented type of web development.

Drupal 8 now runs on an object-oriented framework, Symfony, and it enables you, as a developer, to build on and to extend its whole plugin architecture. So, you either adapt to these changes, getting yourself comfortable with OOP and seizing the opportunity of a plugin structure, or be left behind nurturing your Drupal 7 “nostalgia”!

The fact that Drupal's latest version now runs on Symfony does mean that developers can no longer afford to get “sloppy” when building sites in Drupal 8. You can no longer hope to get off light with poorly written code!

Employing annotations or making sure your code meets the standard for namespaces are just some of the new best practices that you need to adopt as a Drupal 8 developer!

Yet, the new object-oriented specific type of approach towards web development and Drupal 8's whole plugin architecture do come with a “load” of benefits:

  • the reusable web components themselves, that Symfony makes possible now in Drupal 8
     
  • the plugin architecture allows you to contextually extend your Drupal site's functionality 
     
  • you get to build on and to enhance existing plugins; no need to create new ones from scratch and you even get to reuse them in other projects, too!
     
  • when you say plugins in Drupal 8 you say blocks, field formatters, input filters, field types, which used to be components by now
     

3. Your Search: Think It Through Early in Your Drupal 8 Project 

Bid Apache Solr search farewell and greet Drupal 8's Search API!

This shift comes along with a lot more flexibility when it comes to creating indexes: you can decide what will get indexed and the way that those elements will get sorted out, as well.

Implicitly, all this flexibility should be completed by a sense responsibility, from your part, to start thinking through your search from your projects' early stages of development!

Which is your target engine? Can you trigger that functionality, that you're “brewing” in your head right now, from this particular search engine+Search API combo? You'd better have the answers to these questions early in your project! 
 

4. Learn About The New Cache Tags Before Building Sites in Drupal 8

Invest valuable resources of time in learning about Drupal 8's new caching system, in discovering all its in-depths. It will be well-invested time, I assure you!

Cache tags are a lot more flexible, a lot more powerful than in previous versions of Drupal. Yet, before you get to “leverage” their power you need to spend time learning precisely when to set and when to clear your future cache tags.
 

5. No Way Around This: Get Familiarized With Configuration Management 

Otherwise you'll miss a whole bunch of new opportunities that are poking their head up with Drupal 8!

Just remember how frustrating it is in Drupal 7 when you need to apply changes to the configuration stored in your database and:

  • you can't version it
  • you can only move one feature from one website to a another (by leveraging the Features module's power)

And now welcome Drupal 8's configuration management which allows you to:

  • move a whole website from one environment to another
     
  • version settings in the database, export them to code, import them to the production Drupal 8 site and the list of “configuration-related conveniences” can go on

The one and only “trick” is that all your teammates, all the Drupal developers working on a project, need to be more than familiarized with configuration management!
 

6. Embrace the New Modular Way of Using Library Assets in Drupal 8

This, of course, only if you want to make full use of this Drupal 8's enhancement which allows to add libraries only to specific pages of a website. Instead of loading them on every single one.

The modular way in which themes in Drupal 8 use asset libraries to add JS and CSS is “responsible” for this improvement. Basically when you're building sites in Drupal 8 you:

  • get to add your CSS and JS to specific pages only (by simply adding your yourtheme.libraries.yml file to your theme folder)
     
  • get to use libraries for adding external assets to your theme, as well 
     

7. Getting Comfortable With Twig Means Developing Self-Discipline

Order and discipline” will be the two keywords describing your process of building sites in Drupal 8, which now uses... Twig! And a focused self-discipline is what you'll need to start improving yourself, too!

For yes, it's true that Drupal 8's new templating engine “restores” order to the theme layer (thanks to its cleaner syntax), yet you need to restrain yourself from overcrowding your template files.

To overload it with theme PHP, with complex logic, you name it! Discipline is key here for setting a straight line between your display logic and your business logic!

Lesson(s) over! My “teaching” ends here and your own experience as a Drupal 8 developer starts now! Just scan through my tips and tricks, run a selection, think them through and... dare to take the leap to Drupal 8!