Skip to content

Commit fe6f2e6

Browse files
authored
Issue #3116167 by daniel.bosen, alexpott, chr.fritsch, volkerk: Provide option to hide paragraphs drag & drop button
* Add option for drag & drop button * Update README * disable drag & drop in test * Default to paragraphs behaviour
1 parent e3eef5c commit fe6f2e6

6 files changed

+31
-2
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ CONFIGURATION
5050
Paragraphs features for configuration.
5151
3. Select whether you want to reduce the actions dropdown to a button when
5252
there is only one option. Save.
53-
53+
4. Select whether you want to display in between button.
54+
5. Select whether you want to confirm paragraph deletion.
55+
6. Select whether you want to the display the Drag and drop button in the actions menu.
5456

5557
AVAILABLE FEATURES
5658
------------------
@@ -80,6 +82,11 @@ improves UX since one additional click to expand drop-down is removed.
8082
This feature provides a delete confirmation form for the paragraphs experimental
8183
widget UI.
8284

85+
##### Display Drag and drop button
86+
87+
Paragraphs adds a drag & drop button to the action menu, that initiates an advanced drag & drop ui.
88+
You can select if you want this. This feature is only available, if the core/sortable library is
89+
loaded.
8390

8491
MAINTAINERS
8592
-----------

config/schema/paragraphs_features.schema.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ paragraphs_features_third_party:
1919
split_text:
2020
type: boolean
2121
label: 'Flag for paragraphs split text feature'
22+
show_drag_and_drop:
23+
type: boolean
24+
label: 'Flag for showing drag & drop button'
2225

2326
field.widget.third_party.paragraphs_features:
2427
type: paragraphs_features_third_party

paragraphs_features.module

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function paragraphs_features_field_widget_third_party_settings_form(WidgetInterf
4040
}
4141

4242
/**
43-
* Implements hook_paragraphs_behavior_info_alter().
43+
* Implements hook_paragraphs_widget_actions_alter().
4444
*/
4545
function paragraphs_features_paragraphs_widget_actions_alter(array &$widget_actions, array &$context) {
4646
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraphs_entity */

src/ParagraphsFeatures.php

+17
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public static function registerFormWidgetFeatures(array &$elements, ParagraphsWi
5757
$elements['add_more']['#attached']['drupalSettings']['paragraphs_features'][$feature]['_path'] = drupal_get_path('module', 'paragraphs_features');
5858
}
5959
}
60+
// This feature is not part of of the foreach above, since it is not a
61+
// javascript feature, it is a direct modification of the form. If the
62+
// feature is not set, it defaults back to paragraphs behavior.
63+
if (!empty($elements['header_actions']['dropdown_actions']['dragdrop_mode'])) {
64+
$elements['header_actions']['dropdown_actions']['dragdrop_mode']['#access'] = (bool) $widget->getThirdPartySetting('paragraphs_features', 'show_drag_and_drop', TRUE);
65+
}
6066
}
6167

6268
/**
@@ -109,6 +115,17 @@ public static function getThirdPartyForm(WidgetInterface $plugin, $field_name) {
109115
],
110116
];
111117

118+
// Only show the drag & drop feature if we can find the sortable library.
119+
$library_discovery = \Drupal::service('library.discovery');
120+
$library = $library_discovery->getLibraryByName('paragraphs', 'paragraphs-dragdrop');
121+
122+
$elements['show_drag_and_drop'] = [
123+
'#type' => 'checkbox',
124+
'#title' => t('Show drag & drop button'),
125+
'#default_value' => $plugin->getThirdPartySetting('paragraphs_features', 'show_drag_and_drop', TRUE),
126+
'#access' => !empty($library),
127+
];
128+
112129
return $elements;
113130
}
114131

tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ protected function setupParagraphSettings($content_type) {
168168
$this->config('core.entity_form_display.node.' . $content_type . '.default')
169169
->set('content.field_paragraphs.settings.default_paragraph_type', 'test_1')
170170
->set('content.field_paragraphs.settings.add_mode', 'button')
171+
->set('content.field_paragraphs.third_party_settings.paragraphs_features.show_drag_and_drop', FALSE)
171172
->save();
172173

173174
$this->drupalGet($currentUrl);

tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ protected function setupParagraphSettings($content_type) {
137137
// Have a default paragraph, it simplifies the clicking on the edit page.
138138
$this->config('core.entity_form_display.node.' . $content_type . '.default')
139139
->set('content.field_paragraphs.settings.default_paragraph_type', 'test_1')
140+
->set('content.field_paragraphs.third_party_settings.paragraphs_features.show_drag_and_drop', FALSE)
140141
->save();
141142

142143
// Disable duplicate and add_above actions.

0 commit comments

Comments
 (0)