Commit 21807c61 authored by catch's avatar catch
Browse files

Revert "Issue #3314770 by Wim Leers, smustgrave, bnjmnm, alexpott: Enforce...

Revert "Issue #3314770 by Wim Leers, smustgrave, bnjmnm, alexpott: Enforce order of CKEditor 5 plugin settings in config export (as well as other sequences)"

This reverts commit 0f4b07ec.
parent f1e84838
Loading
Loading
Loading
Loading
+0 −24
Original line number Diff line number Diff line
@@ -100,27 +100,3 @@ function ckeditor5_post_update_image_toolbar_item(&$sandbox = []) {

  $config_entity_updater->update($sandbox, 'editor', $callback);
}

/**
 * Updates Text Editors using CKEditor 5 to sort plugin settings by plugin key.
 */
function ckeditor5_post_update_plugins_settings_export_order(&$sandbox = []) {
  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
  $config_entity_updater->update($sandbox, 'editor', function (Editor $editor): bool {
    // Only try to update editors using CKEditor 5.
    if ($editor->getEditor() !== 'ckeditor5') {
      return FALSE;
    }

    $settings = $editor->getSettings();

    // Nothing to do if there are fewer than two plugins with settings.
    if (count($settings['plugins']) < 2) {
      return FALSE;
    }
    ksort($settings['plugins']);
    $editor->setSettings($settings);

    return TRUE;
  });
}
+0 −6
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ editor.settings.ckeditor5:
      mapping:
        items:
          type: sequence
          orderby: ~
          label: 'Items'
          sequence:
            type: ckeditor5.toolbar_item
@@ -21,7 +20,6 @@ editor.settings.ckeditor5:
    plugins:
      type: sequence
      label: 'Plugins'
      orderby: key
      sequence:
        type: ckeditor5.plugin.[%key]
  constraints:
@@ -53,7 +51,6 @@ ckeditor5.plugin.ckeditor5_heading:
  mapping:
    enabled_headings:
      type: sequence
      orderby: value
      label: 'Enabled Headings'
      constraints:
        NotBlank:
@@ -83,7 +80,6 @@ ckeditor5.plugin.ckeditor5_sourceEditing:
  mapping:
    allowed_tags:
      type: sequence
      orderby: ~
      label: 'Allowed Tags'
      sequence:
        type: ckeditor5.element
@@ -99,7 +95,6 @@ ckeditor5.plugin.ckeditor5_alignment:
  mapping:
    enabled_alignments:
      type: sequence
      orderby: value
      label: 'Enabled Alignments'
      constraints:
        NotBlank:
@@ -148,7 +143,6 @@ ckeditor5.plugin.ckeditor5_style:
  mapping:
    styles:
      type: sequence
      orderby: ~
      label: 'Styles'
      constraints:
        NotBlank:
+0 −69
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\ckeditor5\Functional\Update;

use Drupal\editor\Entity\Editor;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;

/**
 * @covers ckeditor5_post_update_plugins_settings_export_order()
 * @group Update
 * @group ckeditor5
 */
class CKEditor5UpdatePluginSettingsSortTest extends UpdatePathTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles() {
    $this->databaseDumpFiles = [
      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz',
    ];
  }

  /**
   * Ensure settings for CKEditor 5 plugins are sorted by plugin key.
   */
  public function testUpdatePluginSettingsSortPostUpdate(): void {
    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_before = array_keys($settings['plugins']);

    $this->runUpdates();

    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_after = array_keys($settings['plugins']);

    // Different sort before and after, but the same values.
    $this->assertNotSame($plugin_settings_before, $plugin_settings_after);
    sort($plugin_settings_before);
    $this->assertSame($plugin_settings_before, $plugin_settings_after);
  }

  /**
   * Ensure settings for CKEditor 5 plugins are sorted by plugin key.
   */
  public function testUpdatePluginSettingsSortEntitySave(): void {
    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_before = array_keys($settings['plugins']);

    $editor->save();

    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_after = array_keys($settings['plugins']);

    // Different sort before and after, but the same values.
    $this->assertNotSame($plugin_settings_before, $plugin_settings_after);
    sort($plugin_settings_before);
    $this->assertSame($plugin_settings_before, $plugin_settings_after);
  }

}
+14 −18
Original line number Diff line number Diff line
@@ -503,10 +503,6 @@ public function test(string $format_id, array $filters_to_drop, array $expected_
      $updated_text_editor->toArray()
    );

    // Save this to ensure the config export order is applied.
    // @see \Drupal\Core\Config\StorableConfigBase::castValue()
    $updated_text_editor->save();

    // We should now have the expected data in the Editor config entity.
    $this->assertSame('ckeditor5', $updated_text_editor->getEditor());
    $this->assertSame($expected_ckeditor5_settings, $updated_text_editor->getSettings());
@@ -932,12 +928,12 @@ public function provider() {
          ),
        ],
        'plugins' => array_merge(
          $basic_html_test_case['expected_ckeditor5_settings']['plugins'],
          [
            'ckeditor5_alignment' => [
              'enabled_alignments' => ['center', 'justify'],
            ],
          ],
          $basic_html_test_case['expected_ckeditor5_settings']['plugins'],
        ),
      ],
      'expected_superset' => implode(' ', [
@@ -1134,10 +1130,6 @@ public function provider() {
              'heading6',
            ],
          ],
          'ckeditor5_list' => [
            'reversed' => FALSE,
            'startIndex' => TRUE,
          ],
          'ckeditor5_sourceEditing' => [
            'allowed_tags' => [
              '<cite>',
@@ -1155,6 +1147,10 @@ public function provider() {
              '<h6 id>',
            ],
          ],
          'ckeditor5_list' => [
            'reversed' => FALSE,
            'startIndex' => TRUE,
          ],
        ],
      ],
      'expected_superset' => '<br> <p>',
@@ -1269,10 +1265,6 @@ public function provider() {
              'heading6',
            ],
          ],
          'ckeditor5_list' => [
            'reversed' => FALSE,
            'startIndex' => TRUE,
          ],
          'ckeditor5_sourceEditing' => [
            'allowed_tags' => [
              '<cite>',
@@ -1290,6 +1282,10 @@ public function provider() {
              '<h6 id>',
            ],
          ],
          'ckeditor5_list' => [
            'reversed' => FALSE,
            'startIndex' => TRUE,
          ],
        ],
      ],
      'expected_superset' => '<br> <p>',
@@ -1376,11 +1372,6 @@ public function provider() {
          ],
        ],
        'plugins' => [
          'ckeditor5_sourceEditing' => [
            'allowed_tags' => [
              '<span>',
            ],
          ],
          'ckeditor5_style' => [
            'styles' => [
              [
@@ -1389,6 +1380,11 @@ public function provider() {
              ],
            ],
          ],
          'ckeditor5_sourceEditing' => [
            'allowed_tags' => [
              '<span>',
            ],
          ],
        ],
      ],
      'expected_superset' => '',
+5 −5
Original line number Diff line number Diff line
@@ -33,11 +33,6 @@ settings:
        - heading4
        - heading5
        - heading6
    ckeditor5_imageResize:
      allow_resize: true
    ckeditor5_list:
      reversed: false
      startIndex: true
    ckeditor5_sourceEditing:
      allowed_tags:
        - '<cite>'
@@ -54,6 +49,11 @@ settings:
        - '<h5 id>'
        - '<h6 id>'
        - '<span>'
    ckeditor5_list:
      reversed: false
      startIndex: true
    ckeditor5_imageResize:
      allow_resize: true
image_upload:
  status: true
  scheme: public
Loading