
Learn some tips about Drupal 8
Share
Table of contents

Learning a new system usually means learning about its little quirks. Drupal 8 has its fair share of quirks. Here are some quick tips that I have learned in the past few months working on my first Drupal 8 project.
### addExpression
Suppose you need to get the last time an item in a table was edited. You can build a dynamic query and, instead of using fields(), you'd use addExpression() like so:
`$query->addExpression('MAX(mod_date)', 'col_alias');`
Now you will get the highest timestamp.
`$timestamp = $query->execute()->fetchField();`
### Differences between `$entity->field_name` and `$entity->get('field_name')`
`$entity->field_name` will return null if the field does not exist while `$entity->get('field_name')` will throw an Exception. Sometimes you'll want one behavior over another so keep that in mind.
### Adding a class to a item list elements
I almost went mad looking for an answer until I dived into the code and learned about `#wrapper_attributes`. Just add this to your item list render array and you're good to go. It will apply those attributes to each `` tag within your item list.
### appendItem
If you need to add a value to a multivalue field in an entity, you can use `appendItem()` to get the job done.
`$entity->field_multivalue->appendItem($some_other_entity_id);`
Over the coming weeks, I or any of my fellow developers here at [Rootstack](http://rootstack.com) will be posting quick tips for other developers new to Drupal 8. I'm sure you will learn a thing or two or, at the very least, we will save you from a mild headache.
Related blogs

Outsourcing IT Bogota: How to hire the right tech partner
January 16th 2026
Looking for IT outsourcing in Bogota? Discover the benefits of nearshoring in Colombia and how to choose the best agency for your software development needs

IT Staff Augmentation in 2026: Why Hire Rootstack?
January 16th 2026
Discover why IT staff augmentation services are vital in 2026 to scale your software development efficiently and with expert talent
6 recommendations for your Docker containers
January 16th 2026
This article lists various simple steps you can take to improve your Docker containers, including reducing build time and size, and enhancing security.

Risks of hiring freelancers vs staff augmentation agencies
January 16th 2026
Freelancers or agency? Discover the risks of hiring independent talent and why IT staff augmentation is the safe solution for scaling

Best countries to hire software developers in 2026
January 14th 2026
Discover why Colombia and Panama will lead the outsourcing market in 2026. A guide for CTOs on staff augmentation and hiring tech talent in Latin America with Rootstack

Top IT Staff Augmentation Companies in the USA: Best Features
January 14th 2026
Discover why increasing your IT staff is key to scaling your software development. Learn how to choose the best partner in the U.S. and why Rootstack is the leading choice.