~/drupal/drupal-advanced-usage-paragraphs-nested-set-fields.md

Drupal 8 - Advanced Usage of the Paragraphs Module

2 min readApril 06, 2020by Gorav Singal#drupal#drupal-8#forms
// 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 the Paragraphs Module

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.

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

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

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…