diff --git a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php index db41ab1..3c48892 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php @@ -174,8 +174,6 @@ public function addInstanceId($id, $configuration = NULL) { if (!isset($this->originalOrder[$id])) { $this->originalOrder[$id] = $id; } - // Ensure the instances are sorted correctly after adding a new instance. - $this->sort(); } /** diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index fb096a7..eb8aad8 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -371,6 +371,7 @@ public function getPluginCollections() { public function addImageEffect(array $configuration) { $configuration['uuid'] = $this->uuidGenerator()->generate(); $this->getEffects()->addInstanceId($configuration['uuid'], $configuration); + $this->getEffects()->sort(); return $configuration['uuid']; } diff --git a/core/modules/image/src/Tests/Update/ImageUpdateEffectOrderTest.php b/core/modules/image/src/Tests/Update/ImageUpdateEffectOrderTest.php new file mode 100644 index 0000000..9b30b4b --- /dev/null +++ b/core/modules/image/src/Tests/Update/ImageUpdateEffectOrderTest.php @@ -0,0 +1,58 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', + __DIR__ . '/../../../tests/fixtures/drupal-8.image-update-effect-order-test.php', + ]; + } + + /** + * Tests image_post_update_image_style_effect_order(). + * + * @see image_post_update_image_style_effect_order() + */ + public function testPostUpdateImageStylesDependencies() { + + $expected_order_in_config = [ + '2fe8084a-0679-46d4-9538-a2ba6917f166', + '59b6b545-7c9e-4f98-ab94-75ac3034259c', + '9d8ffc61-e928-41c9-9e12-7e3484814365', + ]; + + $expected_order_in_plugin_collection = [ + '59b6b545-7c9e-4f98-ab94-75ac3034259c', + '9d8ffc61-e928-41c9-9e12-7e3484814365', + '2fe8084a-0679-46d4-9538-a2ba6917f166', + ]; + + $style = ImageStyle::load('test'); + $this->assertNotIdentical($expected_order_in_config, array_keys($style->get('effects'))); + // Plugin collection will bne osrted correctly because it is sorted by + // weight. + $this->assertIdentical($expected_order_in_plugin_collection, array_keys(iterator_to_array($style->getEffects()->getIterator()))); + + // Run updates. + $this->runUpdates(); + + $style = ImageStyle::load('test'); + $this->assertIdentical($expected_order_in_config, array_keys($style->get('effects'))); + $this->assertIdentical($expected_order_in_plugin_collection, array_keys(iterator_to_array($style->getEffects()->getIterator()))); + } + +} diff --git a/core/modules/image/tests/fixtures/drupal-8.image-update-effect-order-test.php b/core/modules/image/tests/fixtures/drupal-8.image-update-effect-order-test.php new file mode 100644 index 0000000..343b180 --- /dev/null +++ b/core/modules/image/tests/fixtures/drupal-8.image-update-effect-order-test.php @@ -0,0 +1,23 @@ +insert('config') + ->fields(['data', 'name', 'collection']) + ->values([ + 'name' => 'image.style.test', + 'data' => serialize($config), + 'collection' => '', + ]) + ->execute(); diff --git a/core/modules/image/tests/fixtures/image.style.test.yml b/core/modules/image/tests/fixtures/image.style.test.yml new file mode 100644 index 0000000..fe8fa43 --- /dev/null +++ b/core/modules/image/tests/fixtures/image.style.test.yml @@ -0,0 +1,28 @@ +uuid: fab98f81-d3a8-481d-94ba-998d590765c3 +langcode: en +status: true +dependencies: { } +name: test +label: test +effects: + 9d8ffc61-e928-41c9-9e12-7e3484814365: + uuid: 9d8ffc61-e928-41c9-9e12-7e3484814365 + id: image_crop + weight: 2 + data: + width: 400 + height: 400 + anchor: left-top + 59b6b545-7c9e-4f98-ab94-75ac3034259c: + uuid: 59b6b545-7c9e-4f98-ab94-75ac3034259c + id: image_rotate + weight: 1 + data: + degrees: 90 + bgcolor: '' + random: false + 2fe8084a-0679-46d4-9538-a2ba6917f166: + uuid: 2fe8084a-0679-46d4-9538-a2ba6917f166 + id: image_desaturate + weight: 3 + data: { }