drupal|April 06, 2020|2 min read

Drupal 8 - Advanced usage of Paragraphs module - Add nested set of fields and single Add more button (No Coding Required)

TL;DR

Leverage the Paragraphs module to nest paragraph types within each other, enabling complex repeatable field groups with a single Add More button.

Drupal 8 - Advanced usage of Paragraphs module - Add nested set of fields and single Add more button (No Coding Required)

Introduction

In my previous article, I explained How to have set of fields and single Add More button.

In this post, we will see how we can have nested set of fields and we can have a single Add More button for that subset.

Nested Subset and Single Add More button

Let me set context of this article flow. We will discuss following:

Create a content type having fields:

  • Title
  • Body
  • Image for the article
  • Product Details Set (Multiple allowed)

Each Product Details will have following fields:

  • Title
  • Description of product
  • Sub-Product Details (Multiple Allowed)

Each Sub-Product Details will have following fields:

  • Image
  • ASIN code of product

In simpler terms, we will have a content type for a product, in which we can do following:

  • Should be able to add multiple products
  • For each product, we should be able to add multiple images and respective website

Solution

Lets have a look at the step by step guide:

  1. Create a Paragraph Type This is for our Sub-Product details

    • Goto: /admin/structure/paragraphs_type
    • Click on Add Paragraph Type
    • Give a name like Sub-Products
    • Click on Manage fields
    • Add following fields:
      • Product Image
      • ASIN Code of product
      Note: Each of above field is configured to have single value, not multiple. See Using Field Groups for better looking fields
  2. Create another paragraph Type This is for our Product Details

    • Goto: /admin/structure/paragraphs_type
    • Click on Add Paragraph Type
    • Give a name like Products
    • Click on Manage fields
    • Add following fields:
      • Product Title (Text plain)
      • Description of Product (Text Long)
      • Add Paragraph (Under Entity reference), and select above created Paragraph (Product Sub-Details)
      • Above field is set to have Multiple Values.
      See Using Field Groups for better looking fields
  3. Now, create actual Content Type This the actual node for our Product.

    • Create content type, give a name
    • Add following fields
      • Title will comes by default
      • Description field (Text long) This will be an introduction of article
      • Image (For setting main image of article)
      • Now, add Paragraph (From Entity Reference), and select above created Paragraph type: Product Details
      • Set it to have Multiple Values.

Final Look

Lets look at the interested section only.

Drupal Multiple fields example

A more refined image

Drupal Multiple fields example

If you are using Field Groups module, you can have more fun with setting different options for displaying fieldsets.

Related Posts

How to use Docker for Drupal 7 Dev envirnoment

How to use Docker for Drupal 7 Dev envirnoment

I have been using drupal 7 from a long time, and setting up a dev environment…

Drupal 7: How to save a node programmatically and add an image field from a public URL

Drupal 7: How to save a node programmatically and add an image field from a public URL

Note: I have public URLs of these images, which I want to save. return…

Jira Rest APIs common usages

Jira Rest APIs common usages

This article shows some of common usages of JIRA rest apis. Note: This article…

How to sync Mongodb data to ElasticSearch by using MongoConnector

How to sync Mongodb data to ElasticSearch by using MongoConnector

Introduction This post is about syncing your mongodo database data to…

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Introduction I had to write a CICD system for one of our project. I had to…

Eclipse/STS IDE showing compilation errors in java code inspite of all dependencies installed

Eclipse/STS IDE showing compilation errors in java code inspite of all dependencies installed

I have a Java project and dependencies are being managed through maven. I have…

Latest Posts

REST API Design: Pagination, Versioning, and Best Practices

REST API Design: Pagination, Versioning, and Best Practices

Every time two systems need to talk, someone has to design the contract between…

Efficient Data Modelling: A Practical Guide for Production Systems

Efficient Data Modelling: A Practical Guide for Production Systems

Most engineers learn data modelling backwards. They draw an ER diagram…

Deep Dive on Caching: From Browser to Database

Deep Dive on Caching: From Browser to Database

“There are only two hard things in Computer Science: cache invalidation and…

System Design Patterns for Real-Time Updates at High Traffic

System Design Patterns for Real-Time Updates at High Traffic

The previous articles in this series covered scaling reads and scaling writes…

System Design Patterns for Scaling Writes

System Design Patterns for Scaling Writes

In the companion article on scaling reads, we covered caching, replicas, and…

System Design Patterns for Managing Long-Running Tasks

System Design Patterns for Managing Long-Running Tasks

Introduction Some operations simply can’t finish in the time a user is willing…