Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

3.5.7. Data Aggregation in Views.

26/08/2019, by mikhail

The Views module allows not only to output data from the Drupal tables, but it also knows how to calculate this row and group the results. This feature is called aggregation.

By default, Drupal has a Dictionary of Taxonomy Tags. Let's create a block with the most popular tags and display at the end of each tag how many materials on the site with this tag. We get something like this list:

Drupal 9 (5)

Drupal 8 (3)

PHP (2)

To get started, you will need to create Articles and bind tags to them.

/node/add/article

drupal views

After creating a small number of articles, you can get down to business.

/admin/structure/views/add

Add Views block, select Taxonomy and Tags:

Drupal views

Next, you need to enable aggregation in Views:

Drupal aggregation

Now we have additional settings for aggregation in the fields:

drupal view

Now add the RELATIONSHIPS Content with the term:

Drupal

Select Require this rating to count only the content in which the tag is selected:

drupal 8

Now we need two fields of the Term Taxonomy (Name), we hide the first:

drupal 8

To the second field we set the type of aggregation Count:

aggregation

Drupal

Now if you update the preview of the view, then you will already see a count of the amount of use of each of the term taxonomy:

Drupal 8

Now it remains to append the tag name in front of each number. To do this, we use the second field, in which we display the first hidden field and in brackets the value of the second field. To do this, we will use the Overwrite Results setting:

Drupal 8

In the REPLACEMENT PATTERNS drop-down list, we can see which fields we can use when overwriting this field.

{{name}} ({{name_1}})

We write the second field in parentheses round so that our number is in brackets. Curly braces are taken from Twig, we will deal with it later, for now it is enough for us to know that if we use these values in {{}} they will be replaced by the values of the fields we need.

As a result, you should have these fields:

Drupal 8

What should look like this:

Drupal views