Verified Commit f3427282 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3290810 by Spokje, catch, dww, longwave, alexpott: Remove updates added...

Issue #3290810 by Spokje, catch, dww, longwave, alexpott: Remove updates added prior to 9.4.0 (9.4.4 for ckeditor) and add 9.4.0 database dumps
parent 62a402a3
Loading
Loading
Loading
Loading
+5 −31
Original line number Diff line number Diff line
@@ -5,37 +5,11 @@
 * Post update functions for CKEditor.
 */

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\editor\Entity\Editor;

/**
 * Updates Text Editors using CKEditor 4 to omit settings for disabled plugins.
 * Implements hook_removed_post_updates().
 */
function ckeditor_post_update_omit_settings_for_disabled_plugins(&$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 4.
    if ($editor->getEditor() !== 'ckeditor') {
      return FALSE;
    }

    $enabled_plugins = _ckeditor_get_enabled_plugins($editor);

    // Only update if the editor has plugin settings for disabled plugins.
    $needs_update = FALSE;
    $settings = $editor->getSettings();

    // Updates are not needed if plugin settings are not defined for the editor.
    if (!isset($settings['plugins'])) {
      return FALSE;
    }

    foreach (array_keys($settings['plugins']) as $plugin_id) {
      if (!in_array($plugin_id, $enabled_plugins, TRUE)) {
        $needs_update = TRUE;
      }
    }

    return $needs_update;
  });
function ckeditor_removed_post_updates() {
  return [
    'ckeditor_post_update_omit_settings_for_disabled_plugins' => '10.0.0',
  ];
}
+0 −58
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\ckeditor\Functional\Update;

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

/**
 * Tests the update path for CKEditor plugin settings for disabled plugins.
 *
 * @group Update
 */
class CKEditorUpdateOmitDisabledPluginSettings extends UpdatePathTestBase {

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

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

  /**
   * Ensure settings for disabled CKEditor 4 plugins are omitted on post update.
   */
  public function testUpdateUpdateOmitDisabledSettingsPostUpdate() {
    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $this->assertArrayHasKey('stylescombo', $settings['plugins']);

    $this->runUpdates();

    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $this->assertArrayNotHasKey('stylescombo', $settings['plugins']);
  }

  /**
   * Ensure settings for disabled CKEditor 4 plugins are omitted on entity save.
   */
  public function testUpdateUpdateOmitDisabledSettingsEntitySave() {
    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $this->assertArrayHasKey('stylescombo', $settings['plugins']);
    $editor->save();

    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $this->assertArrayNotHasKey('stylescombo', $settings['plugins']);
  }

}
+5 −43
Original line number Diff line number Diff line
@@ -5,49 +5,11 @@
 * Post update functions for CKEditor 5.
 */

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\editor\Entity\Editor;

/**
 * Updates if an already migrated CKEditor 5 configuration for text formats
 * has alignment shown as individual buttons instead of a dropdown.
 * Implements hook_removed_post_updates().
 */
function ckeditor5_post_update_alignment_buttons(&$sandbox = []) {
  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);

  $callback = function (Editor $editor) {
    // Only try to update editors using CKEditor 5.
    if ($editor->getEditor() !== 'ckeditor5') {
      return FALSE;
    }

    $needs_update = FALSE;
    // Only update if the editor is using the non-dropdown buttons.
    $settings = $editor->getSettings();
    $old_alignment_buttons_to_types = [
      'alignment:left' => 'left',
      'alignment:right' => 'right',
      'alignment:center' => 'center',
      'alignment:justify' => 'justify',
function ckeditor5_removed_post_updates() {
  return [
    'ckeditor5_post_update_alignment_buttons' => '10.0.0',
  ];
    if (is_array($settings['toolbar']['items'])) {
      foreach ($old_alignment_buttons_to_types as $button => $type) {
        if (in_array($button, $settings['toolbar']['items'], TRUE)) {
          $settings['toolbar']['items'] = array_values(array_diff($settings['toolbar']['items'], [$button]));
          $settings['plugins']['ckeditor5_alignment']['enabled_alignments'][] = $type;
          if (!in_array('alignment', $settings['toolbar']['items'], TRUE)) {
            $settings['toolbar']['items'][] = 'alignment';
          }
          // Flag this display as needing to be updated.
          $needs_update = TRUE;
        }
      }
    }
    if ($needs_update) {
      $editor->setSettings($settings);
    }
    return $needs_update;
  };

  $config_entity_updater->update($sandbox, 'editor', $callback);
}
+0 −62
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;
use Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait;

/**
 * Tests the update path for CKEditor 5 alignment.
 *
 * @group Update
 */
class CKEditor5UpdateAlignmentTest extends UpdatePathTestBase {

  use CKEditor5TestTrait;

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

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

  /**
   * Tests that CKEditor 5 alignment configurations that are individual buttons
   * are updated to be in dropdown form in the toolbar.
   */
  public function testUpdateAlignmentButtons() {
    $editor = Editor::load('test_format');
    $settings = $editor->getSettings();
    $this->assertContains('alignment:center', $settings['toolbar']['items']);

    $this->runUpdates();

    $expected_toolbar_items = [
      'link',
      'bold',
      'italic',
      'sourceEditing',
      'alignment',
    ];
    $expected_alignment_plugin = [
      'enabled_alignments' => [
        'center',
      ],
    ];
    $editor = Editor::load('test_format');
    $settings = $editor->getSettings();
    $this->assertEquals($expected_toolbar_items, $settings['toolbar']['items']);
    $this->assertEquals($expected_alignment_plugin, $settings['plugins']['ckeditor5_alignment']);
  }

}
+0 −11
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
 * Exposes global functionality for creating image styles.
 */

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Routing\RouteMatchInterface;
@@ -15,7 +14,6 @@
use Drupal\field\FieldStorageConfigInterface;
use Drupal\file\FileInterface;
use Drupal\image\Entity\ImageStyle;
use Drupal\image\ImageConfigUpdater;

/**
 * The name of the query parameter for image derivative tokens.
@@ -370,15 +368,6 @@ function image_entity_presave(EntityInterface $entity) {
  $entity->setSetting('default_image', $default_image);
}

/**
 * Implements hook_ENTITY_TYPE_presave() for entity_view_display.
 */
function image_entity_view_display_presave(EntityViewDisplayInterface $view_display): void {
  $config_updater = \Drupal::classResolver(ImageConfigUpdater::class);
  assert($config_updater instanceof ImageConfigUpdater);
  $config_updater->processImageLazyLoad($view_display);
}

/**
 * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
 */
Loading