diff --git a/core/lib/Drupal/Component/Plugin/PluginBag.php b/core/lib/Drupal/Component/Plugin/PluginBag.php index e37b367..6ac7dd5 100644 --- a/core/lib/Drupal/Component/Plugin/PluginBag.php +++ b/core/lib/Drupal/Component/Plugin/PluginBag.php @@ -101,7 +101,9 @@ public function remove($instance_id) { * The ID of the plugin instance to add. */ public function addInstanceID($id) { - $this->instanceIDs[$id] = $id; + if (!isset($this->instanceIDs[$id])) { + $this->instanceIDs[$id] = $id; + } } /** diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php index 0625cdd..261b25a 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php @@ -85,7 +85,7 @@ public function form(array $form, array &$form_state) { // Render effects below parent elements. '#weight' => 5, ); - foreach ($this->entity->getEffects()->sort() as $effect) { + foreach ($this->entity->getEffects() as $effect) { $key = $effect->getUuid(); $form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL; $form['effects'][$key]['label'] = array( diff --git a/core/modules/image/lib/Drupal/image/ImageEffectBag.php b/core/modules/image/lib/Drupal/image/ImageEffectBag.php index 7d0c8eb..a6a2e92 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectBag.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectBag.php @@ -7,7 +7,6 @@ namespace Drupal\image; -use Drupal\Component\Utility\MapArray; use Drupal\Component\Uuid\Uuid; use Drupal\Component\Plugin\DefaultPluginBag; @@ -63,10 +62,14 @@ public function updateConfiguration(array $configuration) { /** * {@inheritdoc} */ - public function sort() { - uasort($this->configurations, 'drupal_sort_weight'); - $this->instanceIDs = MapArray::copyValuesToKeys(array_keys($this->configurations)); - return $this; + public function sortHelper($aID, $bID) { + $a_weight = $this->get($aID)->getWeight(); + $b_weight = $this->get($bID)->getWeight(); + if ($a_weight == $b_weight) { + return 0; + } + + return ($a_weight < $b_weight) ? -1 : 1; } } diff --git a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php index 73976f9..6a62c15 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php @@ -348,6 +348,7 @@ public function getEffect($effect) { public function getEffects() { if (!$this->effectsBag) { $this->effectsBag = new ImageEffectBag(\Drupal::service('plugin.manager.image.effect'), $this->effects); + $this->effectsBag->sort(); } return $this->effectsBag; } @@ -366,7 +367,7 @@ public function saveImageEffect(array $configuration) { */ public function getExportProperties() { $properties = parent::getExportProperties(); - $properties['effects'] = $this->getEffects()->sort()->getConfiguration(); + $properties['effects'] = $this->getEffects()->getConfiguration(); return $properties; } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index 6bcf733..90b1533 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -156,7 +156,7 @@ function testStyle() { $effect_edits_order = array_keys($effect_edits); $order_correct = TRUE; $index = 0; - foreach ($style->getEffects()->sort() as $effect) { + foreach ($style->getEffects() as $effect) { if ($effect_edits_order[$index] != $effect->getPluginId()) { $order_correct = FALSE; } @@ -203,7 +203,7 @@ function testStyle() { $effect_edits_order = array_reverse($effect_edits_order); $order_correct = TRUE; $index = 0; - foreach ($style->getEffects()->sort() as $effect) { + foreach ($style->getEffects() as $effect) { if ($effect_edits_order[$index] != $effect->getPluginId()) { $order_correct = FALSE; }