Add option to display quick actions on top level paragraphs only

Created on 28 May 2025, 9 days ago

Problem/Motivation

When there are paragraphs inside of a paragraph, eg Accordion paragraph with multiple Accordion items, it's not clear which paragraph quick actions belong to.
In my case Accordion Item always gets a priority to be edited and I can't make quick action for a top level accordion to show up.

Steps to reproduce

Create paragraph inside of a paragraph, try to edit top level paragraph - it's not clear which paragraph quick action shows up for.

Proposed resolution

Add option to display quick actions on top level paragraphs only

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

3.0

Component

Code

Created by

🇦🇺Australia jannakha Brisbane!

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jannakha
  • 🇮🇳India abhishek@kumar

    1.Configuration Setting
    Add a new checkbox in the module's configuration form:

    $form['top_level_only'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Show quick actions for top-level paragraphs only'),
      '#default_value' => $settings['top_level_only'] ?? FALSE,
      '#description' => $this->t('When enabled, quick actions will only appear for paragraphs that are not nested within other paragraphs.'),
    ];
    

    2.Paragraph Detection Logic
    Modify the action rendering logic to check paragraph hierarchy:

    function paragraphs_edit_should_show_actions(ParagraphInterface $paragraph) {
      $config = \Drupal::config('paragraphs_edit.settings');
      
      if ($config->get('top_level_only')) {
        $parent = $paragraph->getParentEntity();
        return !($parent instanceof ParagraphInterface);
      }
      
      return TRUE;
    }
    

    3.JavaScript Modifications
    Update the frontend logic to respect this setting:

    Drupal.behaviors.paragraphsEdit = {
      attach: function (context, settings) {
        if (settings.paragraphsEdit.topLevelOnly) {
          // Only attach handlers to top-level paragraphs
          $(context).find('.paragraph--type:not(.paragraph--type--nested)').once('paragraphs-edit').each(function() {
            // Attach quick actions
          });
        } else {
          // Existing behavior
        }
      }
    };

    New configuration option in /admin/config/content/paragraphs_edit

  • 🇦🇺Australia jannakha Brisbane!

    abhishek@kumar #2 looks good

    please provide a merge request for testing

Production build 0.71.5 2024