From 5d9f8a0f8381e04eb66ab13633d906f5ec0502eb Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Thu, 4 Jan 2024 11:22:06 +0100 Subject: [PATCH 1/7] Add option to disable Collapse all button --- config/schema/paragraphs_features.schema.yml | 5 +++- src/ParagraphsFeatures.php | 30 +++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/config/schema/paragraphs_features.schema.yml b/config/schema/paragraphs_features.schema.yml index 676d639..bc53ff7 100644 --- a/config/schema/paragraphs_features.schema.yml +++ b/config/schema/paragraphs_features.schema.yml @@ -4,7 +4,7 @@ paragraphs_features.settings: mapping: dropdown_to_button: type: boolean - label: 'Flag for reduce actions dropdown to a button when there is only one option' + label: 'Flag to reduce actions dropdown to a button when there is only one option' paragraphs_features_third_party: type: mapping @@ -22,6 +22,9 @@ paragraphs_features_third_party: show_drag_and_drop: type: boolean label: 'Flag for showing drag & drop button' + show_collapse_all: + type: boolean + label: 'Flag to disable collapse all button' field.widget.third_party.paragraphs_features: type: paragraphs_features_third_party diff --git a/src/ParagraphsFeatures.php b/src/ParagraphsFeatures.php index 9f1db63..5da37a8 100644 --- a/src/ParagraphsFeatures.php +++ b/src/ParagraphsFeatures.php @@ -72,7 +72,8 @@ public static function registerFormWidgetFeatures(array &$elements, ParagraphsWi $elements['add_more']['#attached']['library'][] = 'paragraphs_features/scroll_to_element'; foreach (Element::children($elements['add_more']) as $button) { $elements['add_more'][$button]['#ajax']['callback'] = [ - static::class, 'addMoreAjax', + static::class, + 'addMoreAjax', ]; } // This feature is not part of of the foreach above, since it is not a @@ -81,6 +82,13 @@ public static function registerFormWidgetFeatures(array &$elements, ParagraphsWi 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); } + + if (!empty($elements['header_actions']['dropdown_actions']['collapse_all'])) { + $elements['header_actions']['dropdown_actions']['collapse_all']['#access'] = (bool) $widget->getThirdPartySetting('paragraphs_features', 'show_collapse_all', TRUE); + } + if (!empty($elements['header_actions']['actions']['collapse_all'])) { + $elements['header_actions']['actions']['collapse_all']['#access'] = (bool) $widget->getThirdPartySetting('paragraphs_features', 'show_collapse_all', TRUE);; + } } /** @@ -122,6 +130,26 @@ public static function getThirdPartyForm(WidgetInterface $plugin, $field_name) { $disabled = TRUE; } + $elements['show_collapse_all'] = [ + '#type' => 'checkbox', + '#title' => t('Show collapse all button'), + '#default_value' => $plugin->getThirdPartySetting('paragraphs_features', 'show_collapse_all', TRUE), + '#description' => t('Disable the collapse all button when using inline entity forms in your paragraph types.'), + '#states' => [ + 'enabled' => [ + ':input[name="fields[' . $field_name . '][settings_edit_form][settings][features][collapse_edit_all]"]' => [ + #':input[name="fields[' . $field_name . '][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]"]' => [ + 'checked' => TRUE, + ], + ], + 'visible' => [ + ':input[name="fields[' . $field_name . '][settings_edit_form][settings][features][collapse_edit_all]"]' => [ + 'checked' => TRUE, + ], + ], + ], + ]; + $elements['delete_confirmation'] = [ '#type' => 'checkbox', '#title' => t('Enable confirmation on paragraphs remove'), From e3ae2e5b174d01eb6c586712ef912a9ed36cb514 Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Thu, 4 Jan 2024 11:29:27 +0100 Subject: [PATCH 2/7] fix cs --- src/ParagraphsFeatures.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ParagraphsFeatures.php b/src/ParagraphsFeatures.php index 5da37a8..7144693 100644 --- a/src/ParagraphsFeatures.php +++ b/src/ParagraphsFeatures.php @@ -87,7 +87,7 @@ public static function registerFormWidgetFeatures(array &$elements, ParagraphsWi $elements['header_actions']['dropdown_actions']['collapse_all']['#access'] = (bool) $widget->getThirdPartySetting('paragraphs_features', 'show_collapse_all', TRUE); } if (!empty($elements['header_actions']['actions']['collapse_all'])) { - $elements['header_actions']['actions']['collapse_all']['#access'] = (bool) $widget->getThirdPartySetting('paragraphs_features', 'show_collapse_all', TRUE);; + $elements['header_actions']['actions']['collapse_all']['#access'] = (bool) $widget->getThirdPartySetting('paragraphs_features', 'show_collapse_all', TRUE); } } @@ -138,7 +138,6 @@ public static function getThirdPartyForm(WidgetInterface $plugin, $field_name) { '#states' => [ 'enabled' => [ ':input[name="fields[' . $field_name . '][settings_edit_form][settings][features][collapse_edit_all]"]' => [ - #':input[name="fields[' . $field_name . '][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]"]' => [ 'checked' => TRUE, ], ], From 76529fc494db83e8e421f3702b7357dc165b2360 Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Mon, 15 Jan 2024 14:23:32 +0100 Subject: [PATCH 3/7] Add test --- .../ParagraphsFeatureCollapseAllTest.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php diff --git a/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php new file mode 100644 index 0000000..fa31d4c --- /dev/null +++ b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php @@ -0,0 +1,73 @@ +createTestConfiguration($content_type, 1); + $this->setupParagraphSettings($content_type); + + // Check that Edit all and Collapse all buttons are present. + $this->drupalGet("node/add/$content_type"); + $this->scrollClick('xpath', '//input[@data-drupal-selector="field-paragraphs-test-nested-add-more"]'); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $this->assertSession()->elementExists('xpath', '//input[starts-with(@data-drupal-selector,"field-paragraphs-edit-all")]'); + $this->assertSession()->elementExists('xpath', '//input[starts-with(@data-drupal-selector,"field-paragraphs-collapse-all")]'); + + // Enable hide Collapse all option. + $this->drupalGet("admin/structure/types/manage/$content_type/form-display"); + $session = $this->getSession(); + $page = $session->getPage(); + + $page->pressButton('field_paragraphs_settings_edit'); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $page->uncheckField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][show_collapse_all]'); + $this->submitForm([], 'Update'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->submitForm([], $this->t('Save')); + + // Check that Edit all button is and Collapse all button is not present. + $this->drupalGet("node/add/$content_type"); + $this->scrollClick('xpath', '//input[@data-drupal-selector="field-paragraphs-test-nested-add-more"]'); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $this->assertSession()->elementExists('xpath', '//input[starts-with(@data-drupal-selector,"field-paragraphs-edit-all")]'); + $this->assertSession()->elementNotExists('xpath', '//input[starts-with(@data-drupal-selector,"field-paragraphs-collapse-all")]'); + } + + /** + * Setup paragraphs field for a content type. + * + * @param string $content_type + * The content type containing a paragraphs field. + */ + protected function setupParagraphSettings($content_type) { + $currentUrl = $this->getSession()->getCurrentUrl(); + + // 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.settings.add_mode', 'button') + ->set('content.field_paragraphs.third_party_settings.paragraphs_features.show_drag_and_drop', FALSE) + ->set('content.field_paragraphs.settings.features.duplicate', '0') + ->set('content.field_paragraphs.settings.features.collapse_edit_all', 'collapse_edit_all') + ->save(); + + $this->drupalGet($currentUrl); + } +} From 4f86a9f8fef7a207e07823d7aa9273ed0fd07fe5 Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Mon, 15 Jan 2024 14:26:56 +0100 Subject: [PATCH 4/7] fix cs --- .../FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php index fa31d4c..89ff2ef 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php @@ -3,7 +3,8 @@ namespace Drupal\Tests\paragraphs_features\FunctionalJavascript; /** - * Test display of collapse all button according to the show_collapse_all setting. + * Test display of collapse all button according to the show_collapse_all + * setting. * * @group paragraphs_features */ @@ -70,4 +71,5 @@ protected function setupParagraphSettings($content_type) { $this->drupalGet($currentUrl); } + } From 6a232178e5f1045246437e5c90f2768a241e57ff Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Mon, 15 Jan 2024 14:28:19 +0100 Subject: [PATCH 5/7] fix cs --- .../FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php index 89ff2ef..0704ea9 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php @@ -3,8 +3,7 @@ namespace Drupal\Tests\paragraphs_features\FunctionalJavascript; /** - * Test display of collapse all button according to the show_collapse_all - * setting. + * Test the show_collapse_all setting. * * @group paragraphs_features */ From 508e77b9f67650b006ce037ad0fb05c23e062be1 Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Mon, 15 Jan 2024 14:34:26 +0100 Subject: [PATCH 6/7] move worfklow file to trigger --- .github/workflows/{tests.yml => run-tests.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{tests.yml => run-tests.yml} (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/run-tests.yml similarity index 100% rename from .github/workflows/tests.yml rename to .github/workflows/run-tests.yml From d011219506be4dcc348fef679dba463ed786e3eb Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Mon, 15 Jan 2024 14:49:36 +0100 Subject: [PATCH 7/7] Fix Behat\Mink\Exception\DriverException: Only string values can be used for a input element. --- .../ParagraphsFeaturesAddInBetweenTest.php | 6 +++--- .../ParagraphsFeaturesExtendedParagraphsWidgetTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php b/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php index 2ed2c9e..5e42567 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php @@ -43,7 +43,7 @@ public function testAddInBetweenFeature() { $is_option_visible = $session->evaluateScript("Array.from(document.querySelectorAll('.paragraphs-features__add-in-between__option')).filter((item) => { return !item.disabled }).length === 1"); $this->assertEquals(TRUE, $is_option_visible, 'After modal add mode is selected, "add in between" option should be available.'); $page->checkField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]'); - $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', 0); + $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', '0'); $is_checked = $session->evaluateScript("document.querySelector('.paragraphs-features__add-in-between__option').checked"); $this->assertEquals(TRUE, $is_checked, 'Checkbox should be checked.'); @@ -79,7 +79,7 @@ public function testAddInBetweenFeature() { $this->assertSession()->assertWaitOnAjaxRequest(); $page->checkField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]'); - $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', 0); + $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', '0'); $this->submitForm([], 'Update'); $this->assertSession()->assertWaitOnAjaxRequest(); @@ -155,7 +155,7 @@ public function testAddInBetweenFeature() { $session->executeScript("jQuery('[name=\"fields[field_paragraphs][settings_edit_form][settings][add_mode]\"]').trigger('change');"); $this->assertSession()->assertWaitOnAjaxRequest(); $page->checkField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]'); - $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', 0); + $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', '0'); $this->submitForm([], 'Update'); $this->assertSession()->assertWaitOnAjaxRequest(); $this->submitForm([], $this->t('Save')); diff --git a/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php b/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php index 700feb9..0ffca05 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php @@ -43,7 +43,7 @@ public function testAddInBetweenFeature() { $is_option_visible = $session->evaluateScript("Array.from(document.querySelectorAll('.paragraphs-features__add-in-between__option')).filter((item) => { return item.offsetParent }).length === 2"); $this->assertEquals(TRUE, $is_option_visible, 'After modal add mode is selected, "add in between" option should be available.'); $page->checkField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]'); - $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', 0); + $page->fillField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between_link_count]', '0'); $is_checked = $session->evaluateScript("document.querySelector('.paragraphs-features__add-in-between__option').checked"); $this->assertEquals(TRUE, $is_checked, 'Checkbox should be checked.');