diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index b111486..ddf93c7 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -139,7 +139,7 @@ public function save($destination = NULL) { /** * {@inheritdoc} */ - public function apply($operation, array $arguments = array()) { + public function apply($operation, array $arguments = []) { return $this->getToolkit()->apply($operation, $arguments); } @@ -147,56 +147,77 @@ public function apply($operation, array $arguments = array()) { * {@inheritdoc} */ public function createNew($width, $height, $extension = 'png', $transparent_color = '#ffffff') { - return $this->apply('create_new', array('width' => $width, 'height' => $height, 'extension' => $extension, 'transparent_color' => $transparent_color)); + return $this->apply('create_new', [ + 'width' => $width, + 'height' => $height, + 'extension' => $extension, + 'transparent_color' => $transparent_color, + ]); } /** * {@inheritdoc} */ public function convert($extension) { - return $this->apply('convert', array('extension' => $extension)); + return $this->apply('convert', ['extension' => $extension]); } /** * {@inheritdoc} */ public function crop($x, $y, $width, $height = NULL) { - return $this->apply('crop', array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height)); + return $this->apply('crop', [ + 'x' => $x, + 'y' => $y, + 'width' => $width, + 'height' => $height, + ]); } /** * {@inheritdoc} */ public function desaturate() { - return $this->apply('desaturate', array()); + return $this->apply('desaturate', []); } /** * {@inheritdoc} */ public function resize($width, $height) { - return $this->apply('resize', array('width' => $width, 'height' => $height)); + return $this->apply('resize', ['width' => $width, 'height' => $height]); } /** * {@inheritdoc} */ public function rotate($degrees, $background = NULL) { - return $this->apply('rotate', array('degrees' => $degrees, 'background' => $background)); + return $this->apply('rotate', [ + 'degrees' => $degrees, + 'background' => $background, + ]); } /** * {@inheritdoc} */ public function scaleAndCrop($width, $height, $upscale = FALSE) { - return $this->apply('scale_and_crop', array('width' => $width, 'height' => $height, 'upscale' => $upscale)); + return $this->apply('scale_and_crop', [ + 'width' => $width, + 'height' => $height, + 'upscale' => $upscale, + ]); } /** * {@inheritdoc} */ public function scale($width, $height = NULL, $upscale = FALSE) { - return $this->apply('scale', array('width' => $width, 'height' => $height, 'upscale' => $upscale)); + return $this->apply('scale', [ + 'width' => $width, + 'height' => $height, + 'upscale' => $upscale, + ]); } /** diff --git a/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php index 396f03e..4d45df1 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php @@ -22,7 +22,12 @@ class ScaleAndCropImageEffect extends ResizeImageEffect { */ public function applyEffect(ImageInterface $image) { if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'], $this->configuration['upscale'])) { - $this->logger->error('Image scale and crop 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())); + $this->logger->error('Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', [ + '%toolkit' => $image->getToolkitId(), + '%path' => $image->getSource(), + '%mimetype' => $image->getMimeType(), + '%dimensions' => $image->getWidth() . 'x' . $image->getHeight(), + ]); return FALSE; } return TRUE; @@ -32,12 +37,12 @@ public function applyEffect(ImageInterface $image) { * {@inheritdoc} */ public function transformDimensions(array &$dimensions, $uri) { - if ($dimensions['width'] && $dimensions['height']) { + if (isset($dimensions['width'], $dimensions['height'])) { $is_scaled = Image::scaleDimensions($dimensions, $this->configuration['width'], $this->configuration['height'], $this->configuration['upscale']); // If image is not scaled save the original dimensions. if (!$is_scaled) { - return TRUE; + return; } } $dimensions['width'] = $this->configuration['width']; @@ -48,12 +53,9 @@ public function transformDimensions(array &$dimensions, $uri) { * {@inheritdoc} */ public function getSummary() { - $summary = array( - '#theme' => 'image_scale_and_crop_summary', - '#data' => $this->configuration, - ); - $summary += parent::getSummary(); - + $summary = parent::getSummary(); + $summary['#theme'] = 'image_scale_and_crop_summary'; + $summary['#data'] = $this->configuration; return $summary; } @@ -61,9 +63,9 @@ public function getSummary() { * {@inheritdoc} */ public function defaultConfiguration() { - return parent::defaultConfiguration() + array( - 'upscale' => FALSE, - ); + $configuration = parent::defaultConfiguration(); + $configuration['upscale'] = FALSE; + return $configuration; } /** @@ -73,12 +75,12 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $form['width']['#required'] = FALSE; $form['height']['#required'] = FALSE; - $form['upscale'] = array( + $form['upscale'] = [ '#type' => 'checkbox', '#default_value' => $this->configuration['upscale'], '#title' => t('Allow Upscaling'), '#description' => t('Let scale make images larger than their original size'), - ); + ]; return $form; } @@ -97,7 +99,6 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { parent::submitConfigurationForm($form, $form_state); - $this->configuration['upscale'] = $form_state->getValue('upscale'); }