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

Drupal 8 - How to hide help link About text formats and text format guidelines

Drupal 8 - How to hide help link About text formats and text format guidelines

Problem In drupal textarea field, it was always a pain to see the two links…

Drupal - Using Field Groups for Visually Separating multiple field set (No Coding Required)

Drupal - Using Field Groups for Visually Separating multiple field set (No Coding Required)

Introduction You are having a form having multiple fields. When you render a…

Drupal - How to add multiple form fields with a single button click (No Coding Required)

Drupal - How to add multiple form fields with a single button click (No Coding Required)

Introduction Drupal is an awesome CMS. Drupal content type form, allows you to…

Drupal 8 - How to Theme Form and its Fields with reordering fields

Drupal 8 - How to Theme Form and its Fields with reordering fields

Introduction In this post, we will see how to theme form and its fields…

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Introduction I needed a report page, where I wanted to have some information…

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Introduction Assume you have a drupal website and using cloudflare. You are…

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…