diff --git a/core/modules/image/lib/Drupal/image/ConfigurableImageEffectInterface.php b/core/modules/image/lib/Drupal/image/ConfigurableImageEffectInterface.php index f920c92dc9b40eb8b582761c1386df013cd50fe8..292aa4c47d877f80d95c02f1eaf7d72399b8d1ec 100644 --- a/core/modules/image/lib/Drupal/image/ConfigurableImageEffectInterface.php +++ b/core/modules/image/lib/Drupal/image/ConfigurableImageEffectInterface.php @@ -12,14 +12,6 @@ */ interface ConfigurableImageEffectInterface extends ImageEffectInterface { - /** - * Define the effect configuration defaults. - * - * @return array - * An associative array with defaults keyed by configuration names. - */ - public function getConfigurationDefaults(); - /** * Builds the part of the image effect form specific to this image effect. * diff --git a/core/modules/image/lib/Drupal/image/ImageEffectBase.php b/core/modules/image/lib/Drupal/image/ImageEffectBase.php index e8980450d0483ce4311d6600549963aeb261a69f..2babe0d8b83c2b34b759a38097b091a027ac2bee 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectBase.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectBase.php @@ -103,17 +103,10 @@ public function setConfiguration(array $configuration) { 'uuid' => '', 'weight' => '', ); - $this->configuration = $configuration['data'] + $this->getConfigurationDefaults(); + $this->configuration = $configuration['data']; $this->uuid = $configuration['uuid']; $this->weight = $configuration['weight']; return $this; } - /** - * Fallback for non-configurable effects. - */ - public function getConfigurationDefaults() { - return array(); - } - } diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php index 751851ebe2c98d69befba172192b53ef311c6338..e46d2fa74d817e34fbfce40d05a7664c54a525d8 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/CropImageEffect.php @@ -26,6 +26,11 @@ class CropImageEffect extends ResizeImageEffect { * {@inheritdoc} */ public function applyEffect(ImageInterface $image) { + // Set sane default values. + $this->configuration += array( + 'anchor' => 'center-center', + ); + list($x, $y) = explode('-', $this->configuration['anchor']); $x = image_filter_keyword($x, $image->getWidth(), $this->configuration['width']); $y = image_filter_keyword($y, $image->getHeight(), $this->configuration['height']); @@ -49,16 +54,12 @@ public function getSummary() { /** * {@inheritdoc} */ - public function getConfigurationDefaults() { - return parent::getConfigurationDefaults() + array( + public function getForm() { + $this->configuration += array( + 'width' => '', + 'height' => '', 'anchor' => 'center-center', ); - } - - /** - * {@inheritdoc} - */ - public function getForm() { $form = parent::getForm(); $form['anchor'] = array( '#type' => 'radios', diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php index 60f055dccf7b824f9d7b433e65327b23486bec00..766e5a7b87b7fc8dbbc615745be86e3264e3e234 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php @@ -54,16 +54,6 @@ public function getSummary() { ); } - /** - * {@inheritdoc} - */ - public function getConfigurationDefaults() { - return array( - 'width' => NULL, - 'height' => NULL, - ); - } - /** * {@inheritdoc} */ @@ -71,7 +61,7 @@ public function getForm() { $form['width'] = array( '#type' => 'number', '#title' => t('Width'), - '#default_value' => $this->configuration['width'], + '#default_value' => isset($this->configuration['width']) ? $this->configuration['width'] : '', '#field_suffix' => ' ' . t('pixels'), '#required' => TRUE, '#min' => 1, @@ -79,7 +69,7 @@ public function getForm() { $form['height'] = array( '#type' => 'number', '#title' => t('Height'), - '#default_value' => $this->configuration['height'], + '#default_value' => isset($this->configuration['height']) ? $this->configuration['height'] : '', '#field_suffix' => ' ' . t('pixels'), '#required' => TRUE, '#min' => 1, diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php index 2920c7b987ce9b591470744c82d532693bc4a21d..fe563aefb6be4b4f39218fd9a7fb335bff251b37 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php @@ -28,6 +28,13 @@ class RotateImageEffect extends ImageEffectBase implements ConfigurableImageEffe * {@inheritdoc} */ public function applyEffect(ImageInterface $image) { + // Set sane default values. + $this->configuration += array( + 'degrees' => 0, + 'bgcolor' => NULL, + 'random' => FALSE, + ); + // Convert short #FFF syntax to full #FFFFFF syntax. if (strlen($this->configuration['bgcolor']) == 4) { $c = $this->configuration['bgcolor']; @@ -82,24 +89,13 @@ public function getSummary() { ); } - /** - * {@inheritdoc} - */ - public function getConfigurationDefaults() { - return array( - 'degrees' => 0, - 'bgcolor' => NULL, - 'random' => FALSE, - ); - } - /** * {@inheritdoc} */ public function getForm() { $form['degrees'] = array( '#type' => 'number', - '#default_value' => $this->configuration['degrees'], + '#default_value' => (isset($this->configuration['degrees'])) ? $this->configuration['degrees'] : 0, '#title' => t('Rotation angle'), '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'), '#field_suffix' => '°', @@ -107,7 +103,7 @@ public function getForm() { ); $form['bgcolor'] = array( '#type' => 'textfield', - '#default_value' => $this->configuration['bgcolor'], + '#default_value' => (isset($this->configuration['bgcolor'])) ? $this->configuration['bgcolor'] : '#FFFFFF', '#title' => t('Background color'), '#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'), '#size' => 7, @@ -116,7 +112,7 @@ public function getForm() { ); $form['random'] = array( '#type' => 'checkbox', - '#default_value' => $this->configuration['random'], + '#default_value' => (isset($this->configuration['random'])) ? $this->configuration['random'] : 0, '#title' => t('Randomize'), '#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'), ); diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php index 853468842e96597115714a1b414d001249f636f1..c7b2f53ce346d25516c02830fd2c91a544f7766a 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php @@ -27,6 +27,13 @@ class ScaleImageEffect extends ResizeImageEffect { * {@inheritdoc} */ public function applyEffect(ImageInterface $image) { + // Set sane default values. + $this->configuration += array( + 'width' => NULL, + 'height' => NULL, + 'upscale' => FALSE, + ); + if (!$image->scale($this->configuration['width'], $this->configuration['height'], $this->configuration['upscale'])) { watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR); return FALSE; @@ -53,15 +60,6 @@ public function getSummary() { ); } - /** - * {@inheritdoc} - */ - public function getConfigurationDefaults() { - return parent::getConfigurationDefaults() + array( - 'upscale' => FALSE, - ); - } - /** * {@inheritdoc} */ @@ -72,7 +70,7 @@ public function getForm() { $form['height']['#required'] = FALSE; $form['upscale'] = array( '#type' => 'checkbox', - '#default_value' => $this->configuration['upscale'], + '#default_value' => (isset($this->configuration['upscale'])) ? $this->configuration['upscale'] : 0, '#title' => t('Allow Upscaling'), '#description' => t('Let scale make images larger than their original size'), );