6

I'd like to create a content type named image gallery then add two fields as caption as text and image as image. Then make these two bundled and repeatable indefinitely when entering content for this content type.

  • Is it something possible to achieve without using third party modules or creating multiple content types?
  • If so, how?
  • If not, what would you suggest to use to do this?

I've tried to use Paragraph module and working fine but it seems it doesn't provide the image dimensions unless you loop the whole bit and get the dimensions for each item.

PS: Sorry about the tag by the way but it seems tags for content type and structure doesn't exist.

2
  • @Pierre.Vriens sorry my mistake, I meant 3rd party modules not core modules since I couldn't find any proper v8 module for it but I was actually trying to say is it possible to do it by creating content types. If that's not possible, I am OK with any other solution and keen to start with most simple one. I'll try to re-phrase my question in a sec.
    – Tim
    Jan 23, 2017 at 11:26
  • no need for sorry (don't worry). But please do correct your question (by integrating your comment here). Good luck! Jan 23, 2017 at 11:33

2 Answers 2

4

You should look into the new media entity suite of modules for Drupal 8. You can create media bundles and add fields to them (like title, caption, link, copyright). You can then create a simple Paragraph that holds a media reference field, and set it to unlimited - the theming is up to you to get the display to grid out like a gallery. I'm not sure why you need the image dimensions though. But with media entity, media renders out like normal entities meaning they gain access to display modes and various twig template possibilities.

Here is a walkthrough that covers in depth the technique I'm describing and how to set up a media based workflow:

https://www.annertech.com/blog/reusable-media-drupal-8-tutorial

Using Paragraphs is basically the only way to get 'bundled fields' without resorting to using Entity Construction Kit and entity reference fields - but by the time you engineer all that, you'll have spent three times as long and your field data won't live on the media object itself ( which is another drawback to Field Collection), and for that you will definitely want the Media Entity approach. Please don't make them multiple content types either. Media is media.

2

Is it something possible to achieve without using modules or creating multiple content types?

To my knowledge, it is not possible using the modules / features that Drupal 8.2.x Core provides.

Another way, besides using Paragraphs, that I know of is to use the Field Collection module.

You basically create a collection where you add your two fields (both allow only 1 value).

Then add a new field of Type: Field Collection to your content type and change the allowed values from 1 to unlimited.

If you are then using Views to display them, you need to add a relationship of Field Collection.

7
  • I was thinking about the same module ... but you do know the release status is alfa only, right? Or is that release qualifier just misleading (should it be called RC or something)? Jan 23, 2017 at 11:35
  • but you do know the release status is alfa only, right? Correct, but I guess desperate times call for desperate measures, like 168,165 sites did.
    – No Sssweat
    Jan 23, 2017 at 11:40
  • 1
    You're right, it's what I sometimes rephrase to "168,165 sites can't be wrong, so this is clearly a release label that's entirely wrong". I really don't like those module maintainers who never dare to call a release ... a release ... Even if it is not perfect (yet). Oh well ... Jan 23, 2017 at 11:46
  • 1
    Paragraphs is the successor to Field Collection.
    – Kevin
    Jan 23, 2017 at 11:59
  • 1
    On that note I would simply advise to use Paragraphs. I can't imagine FC going much further given the rising popularity of Paragraphs in 8.
    – Kevin
    Jan 23, 2017 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.