Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3412260: Option to disable collapse all button #77

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
5 changes: 4 additions & 1 deletion config/schema/paragraphs_features.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
29 changes: 28 additions & 1 deletion src/ParagraphsFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Drupal\Tests\paragraphs_features\FunctionalJavascript;

/**
* Test the show_collapse_all setting.
*
* @group paragraphs_features
*/
class ParagraphsFeatureCollapseAllTest extends ParagraphsFeaturesJavascriptTestBase {

/**
* Test display of collapse all.
*/
public function testCollapseAllOption() {
// Create content type with paragrapjs field.
$content_type = 'test_collapse_all';

// Create nested paragraph with addition of one text test paragraph.
$this->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);
}

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

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

Expand Down
Loading