Skip to content

Commit

Permalink
Merge branch '2.x' into 3324781-split-text-ckeditor5
Browse files Browse the repository at this point in the history
  • Loading branch information
ol0lll authored Apr 3, 2024
2 parents 84afd93 + 1564ac2 commit 17e271a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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([], '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 @@ -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();

Expand All @@ -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.');

Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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();

Expand Down Expand Up @@ -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");
Expand All @@ -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();

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

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

Expand Down

0 comments on commit 17e271a

Please sign in to comment.