Issue #2052787 by andypost, tim.plunkett, slashrsm: Image style effect ordering exhibits some odd behaviour.
parent
b28f5b817f
commit
2f4b95bae4
|
|
@ -358,6 +358,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface {
|
||||||
public function getEffects() {
|
public function getEffects() {
|
||||||
if (!$this->effectsBag) {
|
if (!$this->effectsBag) {
|
||||||
$this->effectsBag = new ImageEffectBag(\Drupal::service('plugin.manager.image.effect'), $this->effects);
|
$this->effectsBag = new ImageEffectBag(\Drupal::service('plugin.manager.image.effect'), $this->effects);
|
||||||
|
$this->effectsBag->sort();
|
||||||
}
|
}
|
||||||
return $this->effectsBag;
|
return $this->effectsBag;
|
||||||
}
|
}
|
||||||
|
|
@ -376,7 +377,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface {
|
||||||
*/
|
*/
|
||||||
public function getExportProperties() {
|
public function getExportProperties() {
|
||||||
$properties = parent::getExportProperties();
|
$properties = parent::getExportProperties();
|
||||||
$properties['effects'] = $this->getEffects()->sort()->getConfiguration();
|
$properties['effects'] = $this->getEffects()->getConfiguration();
|
||||||
return $properties;
|
return $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class ImageStyleEditForm extends ImageStyleFormBase {
|
||||||
// Render effects below parent elements.
|
// Render effects below parent elements.
|
||||||
'#weight' => 5,
|
'#weight' => 5,
|
||||||
);
|
);
|
||||||
foreach ($this->entity->getEffects()->sort() as $effect) {
|
foreach ($this->entity->getEffects() as $effect) {
|
||||||
$key = $effect->getUuid();
|
$key = $effect->getUuid();
|
||||||
$form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
|
$form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
|
||||||
$form['effects'][$key]['label'] = array(
|
$form['effects'][$key]['label'] = array(
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
namespace Drupal\image;
|
namespace Drupal\image;
|
||||||
|
|
||||||
use Drupal\Component\Utility\MapArray;
|
|
||||||
use Drupal\Component\Plugin\DefaultPluginBag;
|
use Drupal\Component\Plugin\DefaultPluginBag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,10 +50,14 @@ class ImageEffectBag extends DefaultPluginBag {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function sort() {
|
public function sortHelper($aID, $bID) {
|
||||||
uasort($this->configurations, 'drupal_sort_weight');
|
$a_weight = $this->get($aID)->getWeight();
|
||||||
$this->instanceIDs = MapArray::copyValuesToKeys(array_keys($this->configurations));
|
$b_weight = $this->get($bID)->getWeight();
|
||||||
return $this;
|
if ($a_weight == $b_weight) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($a_weight < $b_weight) ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
|
||||||
$effect_edits_order = array_keys($effect_edits);
|
$effect_edits_order = array_keys($effect_edits);
|
||||||
$order_correct = TRUE;
|
$order_correct = TRUE;
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($style->getEffects()->sort() as $effect) {
|
foreach ($style->getEffects() as $effect) {
|
||||||
if ($effect_edits_order[$index] != $effect->getPluginId()) {
|
if ($effect_edits_order[$index] != $effect->getPluginId()) {
|
||||||
$order_correct = FALSE;
|
$order_correct = FALSE;
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +204,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
|
||||||
$effect_edits_order = array_reverse($effect_edits_order);
|
$effect_edits_order = array_reverse($effect_edits_order);
|
||||||
$order_correct = TRUE;
|
$order_correct = TRUE;
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($style->getEffects()->sort() as $effect) {
|
foreach ($style->getEffects() as $effect) {
|
||||||
if ($effect_edits_order[$index] != $effect->getPluginId()) {
|
if ($effect_edits_order[$index] != $effect->getPluginId()) {
|
||||||
$order_correct = FALSE;
|
$order_correct = FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue