What Does Delta Mean in Drupal?
When you are adding Views, you may have seen an extra option called “Delta”.
Several students have asked us about the purpose of this field, because it wasn’t clear.
The Delta option is available throughout the site, but ordinary users are most likely to encounter it inside Views. Here’s how the “Delta” options appear in Views:
And here’s how the Delta fields appear if you add them to your view. It’s really not something you’re likely to want to display.
So what does “Delta” mean?
“Delta” only appears fields which have multiple value. “Delta” refers to the order of the values:
- 0 is the first item
- 1 is the second item
- 2 is the third item etc.
You can use Delta to restrict the results you show. For example, you might only want to show the first and third items stored in a field.
The Delta option isn’t available only in Views. With the “Image Delta Formatter” module, you can use Delta to display fields. In example below, we’re using “0,2” to only show the first and third images:
If you go to the database and find the table for a field with multiple values, you’ll see that the Delta is stored here:
Let’s take another example. Imagine that you have a Date field set up in Drupal 7, and you allow people to choose to repeat the date.
In this situation, every possible repeating date will be stored in the database, with it’s own Delta. The use of the “Delta” fields allows you choose only some of the many possible dates.
One of my beefs with delta, since the ice age, is that it is an integer and when working with ajax, all hell breaks loose. I’m still very surprised Drupal 8 hasn’t shipped with uuids as deltas.
Good point, Ivan
90% of the time, I explain Delta in this way: “This is what it is. You’ll likely never use it.”
Thanks, I’ve been wondering what a delta was for the longest time. Thanks for the clear and understandable explanation.
Thanks Nancy. I needed it myself. I’d often glossed over it while teaching.
I have worked with Drupal for 7 years and have never really liked the word delta as it’s not intuitive, even for a native english speaker. It’s actually a latin word which simply means ‘difference’ and in this context is the key that differentiates between a set of ‘objects’, items or things, often stored in a traditional PHP array.
However it is not always an integer, but in some places can be a string key, like a machine name, e.g. in the block plugin API: [url=https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_view/7]https://api.drupal.org/api/…[/url]
Thanks Andy. That’s a great point that I didn’t cover in the blog.
It doesn’t have to be a number.
Very interesting. Thanks for sharing.
thanks
Thanks for clarification. Very helpful howto!!
Is there a difference between delta and weight?
[quote=Ivan Jaros]One of my beefs with delta, since the ice age, is that it is an integer and when working with ajax, all hell breaks loose. I’m still very surprised Drupal 8 hasn’t shipped with uuids as deltas.bhhgbhbcfttfezsfv [/quote]