Issue #2052787 by andypost, tim.plunkett, slashrsm: Image style effect ordering exhibits some odd behaviour.

8.0.x
Nathaniel Catchpole 2013-11-29 10:08:12 +00:00
parent b28f5b817f
commit 2f4b95bae4
4 changed files with 13 additions and 9 deletions

View File

@ -358,6 +358,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface {
public function getEffects() {
if (!$this->effectsBag) {
$this->effectsBag = new ImageEffectBag(\Drupal::service('plugin.manager.image.effect'), $this->effects);
$this->effectsBag->sort();
}
return $this->effectsBag;
}
@ -376,7 +377,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface {
*/
public function getExportProperties() {
$properties = parent::getExportProperties();
$properties['effects'] = $this->getEffects()->sort()->getConfiguration();
$properties['effects'] = $this->getEffects()->getConfiguration();
return $properties;
}

View File

@ -72,7 +72,7 @@ class ImageStyleEditForm extends ImageStyleFormBase {
// 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(

View File

@ -7,7 +7,6 @@
namespace Drupal\image;
use Drupal\Component\Utility\MapArray;
use Drupal\Component\Plugin\DefaultPluginBag;
/**
@ -51,10 +50,14 @@ class ImageEffectBag extends DefaultPluginBag {
/**
* {@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;
}
}

View File

@ -156,7 +156,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
$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;
}
@ -204,7 +204,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
$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;
}