Hello, let me explain what I'm trying to do:

I'm using the Media core module to store images. I created a new taxonomy vocabulary named "Albums" and then I added a new field under Image media type to reference the "Albums" taxonomy, so the user can assign the images to Albums.

I've created a new view to show the albums. The view should show the album most recent image and the album title. So when I created the view, I changed it to display Taxonomy vocabulary of type "Albums". I changed the format to "Grid", show "Fields". I created a new Relationship with Image album field, and under Fields I added the taxonomy name and then the image field of Image media type. Now the View is showing all images of all albums, instead of the first one. How can I limit to just 1 picture? (Preferable to be the most recent one)

I've made a quick research and usually people tell to use modules, but all of them are for version 7.x, and I'm using 8.x. If there's a way in the core to do this, this would be preferable.

Comments

Bluelake’s picture

Hello,

I have not fully understood what you require, but it looks to me as though you need to restrict the view display to show only 1 item. For this you need to edit the view >> use pager (select "display specified number of items") and then select the number of items per page as 1. Then you need to sort the view by post date.

Hope this helps,

Bluelake

andresilva.cc’s picture

Thank you for your answer, but this is not the problem I'm facing.

The view should display ALL albums. An "Album" is a taxonomy vocabulary. So I created a new view to display taxonomy terms from vocabulary "Album", this is working just fine. Inside Image media type, I have a new field which references an Album taxonomy term, so the user can assign images to Albums. The problem is: I need to show the Albums with their respective latest pictures in the album cover, just like a media gallery.

I could get to make a relationship in the view with Image album reference field, but it'll show all Images from each Album, where I need to limit to just the most recent image.

Harsikesa’s picture

Hello,

Same here, its very difficult in Drupal 8 to achive this. But this is really essential things. I need to limit the multi value field relationship to only one value. If not, I will get so much duplicate on the node field, as every single value of multi value field will have the same value of node title.

How to reproduce:

  1. Create an Image field in Article content type with unlimited value
  2. Upload a more than one image to Article, for example 10 images, and fill the title field, body, etc
  3. Create a Views with content type Node, add some field to it for example Title or Body field
  4. Add relationship to Image field
  5. Then you will see so much duplicate of the title field because every title has a different image from the result of relationship
  6. This... we need to limit to only 1 image, regardless we uploaded 10 images or more
  7. Ughs.. 

any help would be much appreciated!

Harsikesa’s picture

You can simply resolve this without any code from the UI as the following:
- Add a new ID field and exclude it from the display
- Activate aggregation
- Configure the ID field aggregation to "Group results together" (A)
- set Group column to "Entity ID" (B)
- Set every field to A&B