
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

Best Machine Learning and Data Science Software: Technical Guide 2026
January 7th 2026
Looking for machine learning software? We analyze the best tools (TensorFlow, Vertex AI, Databricks) from a business development perspective.

Data Science and Machine Learning: Unlocking its benefits
January 6th 2026
Discover how Rootstack applies data science, AI, and ML to transform your business. Explore the benefits of machine learning and real-world use cases.

Things to consider when selecting Nearshore Partner
January 4th 2026
Developing a software is a complex, time-consuming and usually expensive task. Choosing to outsource part of the entire development team to a nearshore development partner can be a wise choice. Not only because it is relatively affordable and cost-effective, but because it offers a new set of benefits for growing business that are looking to expand their reach.

Open banking vs. open finance: platforms, APIs, and use cases
December 17th 2025
Discover the differences between open banking and open finance. Learn about platforms, bank account APIs, and use cases to scale your fintech business

Embedded Fintech: Payments, Investment, and APIs that drive growth
December 17th 2025
At Rootstack, we understand that adopting these technologies isn't just a software update; it's a business model evolution. In this article, we'll explore how the right infrastructure—from payments to robust APIs—can catalyze sustainable growth

AI in Fintech: Use cases and practical applications of artificial intelligence in banking and finance
December 17th 2025
Throughout this article, we will explore how AI in banking and finance is reshaping the ecosystem, what the most profitable use cases are, and why having a specialized technical partner is vital for successful deployment