Can't switch off "Show arrows for drag & drop" setting for nested paragraph lists

Created on 8 October 2024, 3 months ago

Problem/Motivation

When you have a paragraph field on a paragraph, and you turn off the "Show arrows for drag & drop" setting on the form display settings, it does not work, the arrows are still visible.

I don't think this below function is using the "getThirdPartySetting" method correctly:

  public static function registerWidgetFeatures(array &$elements, ParagraphsWidget $widget): void {
    if (<strong>$widget->getThirdPartySetting('paragraphs_ee', 'paragraphs_ee', 'drag_drop')</strong>) {
      $elements['#attached']['library'][] = 'paragraphs_ee/paragraphs_ee.drag_drop';
      $elements['#attached']['drupalSettings']['paragraphs_ee']['widgetTitle'] = $widget->getSetting('title');
      foreach (Element::children($elements) as $key) {
        $elements[$key]['top']['#attributes']['class'][] = 'drag-drop-buttons';
      }
    }
  }

I think it should be:

  public static function registerWidgetFeatures(array &$elements, ParagraphsWidget $widget): void {
    if ($settings = $widget->getThirdPartySetting('paragraphs_ee', 'paragraphs_ee')) {
      if (isset($settings['drag_drop']) && $settings['drag_drop']) {
        $elements['#attached']['library'][] = 'paragraphs_ee/paragraphs_ee.drag_drop';
        $elements['#attached']['drupalSettings']['paragraphs_ee']['widgetTitle'] = $widget->getSetting('title');
        foreach (Element::children($elements) as $key) {
          $elements[$key]['top']['#attributes']['class'][] = 'drag-drop-buttons';
        }
      }
    }
  }

However, this doesn't work for nested paragraphs because I think the "paragraphs_ee/paragraphs_ee.drag_drop" library is not loaded. Can we load the library regardless? Or is there a way to load it on an ajax call i.e. the call that opens the paragraph and triggers the registerWidgetFeatures function?

🐛 Bug report
Status

Active

Version

10.0

Component

Code

Created by

🇬🇧United Kingdom joehuggans Harrogate, UK

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

Comments & Activities

  • Issue created by @joehuggans
  • 🇬🇧United Kingdom joehuggans Harrogate, UK
  • 🇬🇧United Kingdom joehuggans Harrogate, UK
  • 🇬🇧United Kingdom joehuggans Harrogate, UK
  • 🇬🇧United Kingdom joehuggans Harrogate, UK

    Apologies I have made a bit of a dogs dinner of this issue description.

    I just want to report however that the following is working for me, I can turn off the setting for BOTH 1st and 2st level paragraphs.

    I don't know enough about this module to feel comfortable making a MR on this, and I don't think adding the library here is probably correct.

    In summary, the getThirdPartySetting method was not correct, I changed it from
    $widget->getThirdPartySetting('paragraphs_ee', 'paragraphs_ee', 'drag_drop')
    to
    $widget->getThirdPartySetting('paragraphs_ee', 'paragraphs_ee')

    I then checked for the 'drag_drop' key value in the returned value, and I add the class 'drag-drop-buttons'.

    I am adding the "paragraphs_ee/paragraphs_ee.drag_drop" library outside of the if statement because it doesn't seem to work on an AJAX call (when the nested paragraph is opened.)

      public static function registerWidgetFeatures(array &$elements, ParagraphsWidget $widget): void {
        $elements['#attached']['library'][] = 'paragraphs_ee/paragraphs_ee.drag_drop';
        if ($settings = $widget->getThirdPartySetting('paragraphs_ee', 'paragraphs_ee')) {
          if (isset($settings['drag_drop']) && $settings['drag_drop']) {
            $elements['#attached']['drupalSettings']['paragraphs_ee']['widgetTitle'] = $widget->getSetting('title');
            foreach (Element::children($elements) as $key) {
              $elements[$key]['top']['#attributes']['class'][] = 'drag-drop-buttons';
            }
          }
        }
      }
    
    • cd51d9b7 committed on 10.0.x
      Issue #3479390 by joe huggans: Can't switch off "Show arrows for drag...
  • 🇩🇪Germany stborchert

    Thanks a lot! The call to ->getThirdPartySettings() was totally wrong, indeed. I fixed this based on your suggestion.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024