Views: possibilities with the core module

In this exercise we will try out all the possibilities within the view core module. Views has many more extension modules, but this is for later. Some reference knowlegdge is neede for this exercise as we are comining two content types. Views and references are in the core so you don't have to install anything.

We handle the following subjects:

In the core:

View types:

  • page
  • block
  • attachment
  • entity reference
  • feed

Display content in

  • tables
  • grids
  • formatted list
  • unformatted list
  • fields

Configurations:

  • Filter
  • Show filters in a block
  • Sort
  • Paging
  • Header and footer
  • Roles
  • When there is no content
  • Contextual filters
  • Relations
  • Query
  • Aggragation
  • CSS

Make 2 content types who are related to eachother. EG Painters and paintings. Each content type has a body and image field. The paintings are linked with a content reference towards the painters. I have 2 painters: Gustav Klimt and Pablo Picasso. Each with 2 paintings. (source Wikipedia)
 

Drupal8_001390.png
Drupal8_001391.png

Make a view with a page where the paintings are beiing shown. Try out the possibilities.

Unordered list:

Drupal8_001360.png

Ordered:
Drupal8_001361.png

Grid:
Drupal8_001362.png

Table with fields:


Drupal8_001364.png

The field structure
Drupal8_001365.png

You can set the rights:


Drupal8_001366.png

Rewriting the results combining 2 fields and adding some CSS class. Use tokens to do so.

Drupal8_001370.png
Drupal8_001371.png

Now we want the picure from the painter as well. It is in the other content type! So we can not access it directly. Mak a relation first and then you can add the field.


Drupal8_001372.png

Use the relation in the field configuration:
Drupal8_001373.png

With the configuration of the table you can put content in the same column. An example:
Drupal8_001374.png

Paging:
Drupal8_001375.png

Exposed filters:


Drupal8_001376.png

Probeer eens de groepering uit.

Drupal8_001380.png

Head and footer of a view:

Drupal8_001382.png

What if there are no results? Add a message.


Drupal8_001383.png

Table headers can be sticky and stay always at the top of your view.


Drupal8_001384.png

Sometimes when working with relations, you can get dubble output. Setting the distinct option you avoid this problem.


Drupal8_001385.png

Put all the filters in one block.


Drupal8_001386.png

A contextual filter, filters with the URL. This is important and it has many advantages in combination with soma other view modules as Viewfield and EVA (entity view attachment). Now i don't want to use external view modules, so relax... I only show the way of filtering.
Drupal8_001387.png

You see nothing unless you fill in the name of the painter.


Drupal8_001388.png

In the URL you can see the painter and below the filtering.


Drupal8_001389.png

Aggregation is beiing used for counting, averages,.... Make a attachment view and counts how many paintings we have in the content type. Add this below the view of the paintings.

Used modules