Skip to content

Commit

Permalink
Issue #3116167 by daniel.bosen, alexpott, chr.fritsch, volkerk: Provi…
Browse files Browse the repository at this point in the history
…de option to hide paragraphs drag & drop button

* Add option for drag & drop button

* Update README

* disable drag & drop in test

* Default to paragraphs behaviour
  • Loading branch information
chrfritsch authored Feb 26, 2020
1 parent e3eef5c commit fe6f2e6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down Expand Up @@ -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
-----------
Expand Down
3 changes: 3 additions & 0 deletions config/schema/paragraphs_features.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion paragraphs_features.module
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
17 changes: 17 additions & 0 deletions src/ParagraphsFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fe6f2e6

Please sign in to comment.