diff --git a/README.md b/README.md index 67e0aa6..5e6cf25 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ CONFIGURATION Paragraphs features for configuration. 3. Select whether you want to reduce the actions dropdown to a button when there is only one option. Save. - + 4. Select whether you want to display in between button. + 5. Select whether you want to confirm paragraph deletion. + 6. Select whether you want to the display the Drag and drop button in the actions menu. AVAILABLE FEATURES ------------------ @@ -80,6 +82,11 @@ improves UX since one additional click to expand drop-down is removed. This feature provides a delete confirmation form for the paragraphs experimental widget UI. +##### Display Drag and drop button + +Paragraphs adds a drag & drop button to the action menu, that initiates an advanced drag & drop ui. +You can select if you want this. This feature is only available, if the core/sortable library is +loaded. MAINTAINERS ----------- diff --git a/config/schema/paragraphs_features.schema.yml b/config/schema/paragraphs_features.schema.yml index 6e24a28..c0826ae 100644 --- a/config/schema/paragraphs_features.schema.yml +++ b/config/schema/paragraphs_features.schema.yml @@ -19,6 +19,9 @@ paragraphs_features_third_party: split_text: type: boolean label: 'Flag for paragraphs split text feature' + show_drag_and_drop: + type: boolean + label: 'Flag for showing drag & drop button' field.widget.third_party.paragraphs_features: type: paragraphs_features_third_party diff --git a/paragraphs_features.module b/paragraphs_features.module index 5a9e46f..ed7d7c4 100644 --- a/paragraphs_features.module +++ b/paragraphs_features.module @@ -40,7 +40,7 @@ function paragraphs_features_field_widget_third_party_settings_form(WidgetInterf } /** - * Implements hook_paragraphs_behavior_info_alter(). + * Implements hook_paragraphs_widget_actions_alter(). */ function paragraphs_features_paragraphs_widget_actions_alter(array &$widget_actions, array &$context) { /** @var \Drupal\paragraphs\Entity\Paragraph $paragraphs_entity */ diff --git a/src/ParagraphsFeatures.php b/src/ParagraphsFeatures.php index f04f53a..034363b 100644 --- a/src/ParagraphsFeatures.php +++ b/src/ParagraphsFeatures.php @@ -57,6 +57,12 @@ public static function registerFormWidgetFeatures(array &$elements, ParagraphsWi $elements['add_more']['#attached']['drupalSettings']['paragraphs_features'][$feature]['_path'] = drupal_get_path('module', 'paragraphs_features'); } } + // This feature is not part of of the foreach above, since it is not a + // javascript feature, it is a direct modification of the form. If the + // feature is not set, it defaults back to paragraphs behavior. + if (!empty($elements['header_actions']['dropdown_actions']['dragdrop_mode'])) { + $elements['header_actions']['dropdown_actions']['dragdrop_mode']['#access'] = (bool) $widget->getThirdPartySetting('paragraphs_features', 'show_drag_and_drop', TRUE); + } } /** @@ -109,6 +115,17 @@ public static function getThirdPartyForm(WidgetInterface $plugin, $field_name) { ], ]; + // Only show the drag & drop feature if we can find the sortable library. + $library_discovery = \Drupal::service('library.discovery'); + $library = $library_discovery->getLibraryByName('paragraphs', 'paragraphs-dragdrop'); + + $elements['show_drag_and_drop'] = [ + '#type' => 'checkbox', + '#title' => t('Show drag & drop button'), + '#default_value' => $plugin->getThirdPartySetting('paragraphs_features', 'show_drag_and_drop', TRUE), + '#access' => !empty($library), + ]; + return $elements; } diff --git a/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php b/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php index bf9d8b8..5e6ebc4 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php @@ -168,6 +168,7 @@ protected function setupParagraphSettings($content_type) { $this->config('core.entity_form_display.node.' . $content_type . '.default') ->set('content.field_paragraphs.settings.default_paragraph_type', 'test_1') ->set('content.field_paragraphs.settings.add_mode', 'button') + ->set('content.field_paragraphs.third_party_settings.paragraphs_features.show_drag_and_drop', FALSE) ->save(); $this->drupalGet($currentUrl); diff --git a/tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php b/tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php index 13415cb..a498091 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php @@ -137,6 +137,7 @@ protected function setupParagraphSettings($content_type) { // Have a default paragraph, it simplifies the clicking on the edit page. $this->config('core.entity_form_display.node.' . $content_type . '.default') ->set('content.field_paragraphs.settings.default_paragraph_type', 'test_1') + ->set('content.field_paragraphs.third_party_settings.paragraphs_features.show_drag_and_drop', FALSE) ->save(); // Disable duplicate and add_above actions.