diff --git a/.github/workflows/tests.yml b/.github/workflows/run-tests.yml similarity index 97% rename from .github/workflows/tests.yml rename to .github/workflows/run-tests.yml index 898a8f7..21819b1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/run-tests.yml @@ -37,7 +37,7 @@ jobs: strategy: matrix: THEME: ['claro', 'gin'] - DRUPAL_TESTING_DRUPAL_VERSION: ['~9.5.0', '~10.1.0'] + DRUPAL_TESTING_DRUPAL_VERSION: ['~10.1.0', '~10.2.0'] PHP_VERSION: ['8.1'] steps: 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..7144693 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,25 @@ 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]"]' => [ + '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'), diff --git a/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php new file mode 100644 index 0000000..5f3da17 --- /dev/null +++ b/tests/src/FunctionalJavascript/ParagraphsFeatureCollapseAllTest.php @@ -0,0 +1,74 @@ +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([], '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); + } + +} diff --git a/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php b/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php index 2ed2c9e..185dec1 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php @@ -27,7 +27,6 @@ public function testAddInBetweenFeature() { $session = $this->getSession(); $page = $session->getPage(); $driver = $session->getDriver(); - $page->pressButton('field_paragraphs_settings_edit'); $this->assertSession()->assertWaitOnAjaxRequest(); @@ -43,7 +42,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.'); @@ -66,7 +65,7 @@ public function testAddInBetweenFeature() { $this->submitForm([], 'Update'); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->submitForm([], $this->t('Save')); + $this->submitForm([], 'Save'); // Check that default add mode functionality is used. $this->drupalGet("node/add/$content_type"); @@ -79,11 +78,11 @@ 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(); - $this->submitForm([], $this->t('Save')); + $this->submitForm([], 'Save'); // Check that add in between functionality is used. $this->drupalGet("node/add/$content_type"); @@ -93,7 +92,6 @@ public function testAddInBetweenFeature() { // Add a nested paragraph and check that add in between is used only for // base paragraphs field, but not for the nested paragraph. $session->executeScript("document.querySelector('.paragraphs-features__add-in-between__button').click()"); - $this->assertSession()->assertWaitOnAjaxRequest(); $page->find('xpath', '//*[contains(@class, "paragraphs-add-dialog") and contains(@class, "ui-dialog-content")]//*[contains(@name, "test_nested")]')->click(); $this->assertSession()->assertWaitOnAjaxRequest(); @@ -145,7 +143,7 @@ public function testAddInBetweenFeature() { $page->uncheckField('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][add_in_between]'); $this->submitForm([], 'Update'); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->submitForm([], $this->t('Save')); + $this->submitForm([], 'Save'); // Set modal add mode with add in between option for nested paragraph. $this->drupalGet("admin/structure/paragraphs_type/test_nested/form-display"); @@ -155,17 +153,16 @@ 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')); + $this->submitForm([], 'Save'); // Check that add in between functionality is not available for base // paragraphs and it's used for nested paragraph. $this->drupalGet("node/add/$content_type"); $session->executeScript("document.querySelector('.paragraph-type-add-modal-button').click()"); - $this->assertSession()->assertWaitOnAjaxRequest(); $page->find('xpath', '//*[contains(@class, "paragraphs-add-dialog") and contains(@class, "ui-dialog-content")]//*[contains(@name, "test_nested")]')->click(); $this->assertSession()->assertWaitOnAjaxRequest(); diff --git a/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php b/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php index 9f69b36..5037efe 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php @@ -231,7 +231,7 @@ protected function toggleDeleteConfirmation($content_type, $op = 'check') { $page->$action('fields[field_paragraphs][settings_edit_form][third_party_settings][paragraphs_features][delete_confirmation]'); $this->submitForm([], 'Update'); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->submitForm([], $this->t('Save')); + $this->submitForm([], 'Save'); } } diff --git a/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php b/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php index 700feb9..cd414f7 100644 --- a/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php @@ -43,14 +43,14 @@ 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.'); $this->submitForm([], 'Update'); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->submitForm([], $this->t('Save')); + $this->submitForm([], 'Save'); // Check that add in between functionality is used. $this->drupalGet("node/add/$content_type"); @@ -60,7 +60,6 @@ public function testAddInBetweenFeature() { // Add a nested paragraph and check that add in between is used only for // base paragraphs field, but not for the nested paragraph. $session->executeScript("document.querySelector('.paragraphs-features__add-in-between__button').click()"); - $this->assertSession()->assertWaitOnAjaxRequest(); $page->find('xpath', '//*[contains(@class, "paragraphs-add-dialog") and contains(@class, "ui-dialog-content")]//*[contains(@name, "test_nested")]')->click(); $this->assertSession()->assertWaitOnAjaxRequest();