Tags: Technologies, Managed Teams, IT Staff Augmentation
Share
Table of contents
Quick Access
![Learn some tips about Drupal 8 - Rootstack](https://cms.rootstack.comhttps://cms.rootstack.com/sites/default/files/blog/img/untitled-1.png)
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
What are the types of artificial intelligence?
November 13, 2024
Tags: Technologies
In this article we will explore the main types of artificial intelligence, from the most basic to the most advanced, and how they can transform the way you operate in your company
This article explores the fundamentals of responsible AI and why it is essential for companies looking to implement innovative solutions without compromising ethical values or facing legal risks
Este artículo explora los fundamentos de la IA responsable y por qué es esencial para empresas que buscan implementar soluciones innovadoras sin comprometer valores éticos o enfrentar riesgos legales
In this article, we will explore how this tool is transforming the maritime industry, from optimizing routes to improving sustainability, and how your company can take advantage of its potential
In this article, we will explore how NLP can be implemented in healthcare, the benefits it brings, and why it is a smart investment for medical institutions looking to stay ahead of the curve
What are neural networks and how can I use them in my business?
November 12, 2024
Tags: Technologies
In this article, we will explore what neural networks are, how they work, and how you can implement them in your business to boost innovation and productivity