Commit a6d19bf7 authored by alexpott's avatar alexpott

Issue #2063403 by claudiu.cristea: Fixed Fatal when editing a nonexistent image effect.

parent 04b4a96c
......@@ -7,9 +7,8 @@
namespace Drupal\Component\Plugin;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Exception\UnknownPluginException;
use Drupal\Component\Utility\MapArray;
use Drupal\Component\Utility\String;
/**
* Provides a default plugin bag for a plugin type.
......@@ -76,7 +75,7 @@ public function __construct(PluginManagerInterface $manager, array $configuratio
protected function initializePlugin($instance_id) {
$configuration = isset($this->configurations[$instance_id]) ? $this->configurations[$instance_id] : array();
if (!isset($configuration[$this->pluginKey])) {
throw new PluginException(String::format("Unknown plugin ID '@instance'.", array('@instance' => $instance_id)));
throw new UnknownPluginException($instance_id);
}
$this->pluginInstances[$instance_id] = $this->manager->createInstance($configuration[$this->pluginKey], $configuration);
$this->addInstanceID($instance_id);
......
<?php
/**
* @file
* Contains \Drupal\Component\Plugin\Exception\UnknownPluginException.
*/
namespace Drupal\Component\Plugin\Exception;
use Drupal\Component\Utility\String;
/**
* Plugin exception class to be thrown when a nonexistent plugin was requested.
*/
class UnknownPluginException extends PluginException {
/**
* Construct an UnknownPluginException exception.
*
* @param string $instance_id
* The invalid instance ID that failed.
*
* @see \Exception for remaining parameters.
*/
public function __construct($instance_id, $message = '', $code = 0, \Exception $previous = NULL) {
if (empty($message)) {
$message = String::format("Unknown plugin ID '@instance'.", array('@instance' => $instance_id));
}
parent::__construct($message, $code, $previous);
}
}
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Component\Plugin\Exception\UnknownPluginException;
use Drupal\field\Entity\Field;
use Drupal\field\Entity\FieldInstance;
use Drupal\file\Entity\File;
......@@ -72,8 +73,14 @@ function image_help($path, $arg) {
$effect = \Drupal::service('plugin.manager.image.effect')->getDefinition($arg[7]);
return isset($effect['description']) ? ('<p>' . $effect['description'] . '</p>') : NULL;
case 'admin/config/media/image-styles/manage/%/effects/%':
$effect = entity_load('image_style', $arg[5])->getEffect($arg[7])->getPluginDefinition();
return isset($effect['description']) ? ('<p>' . $effect['description'] . '</p>') : NULL;
try {
$effect = entity_load('image_style', $arg[5])->getEffect($arg[7]);
}
catch (UnknownPluginException $e) {
return NULL;
}
$effect_definition = $effect->getPluginDefinition();
return isset($effect_definition['description']) ? ('<p>' . $effect_definition['description'] . '</p>') : NULL;
}
}
......
......@@ -10,6 +10,8 @@
use Drupal\Core\Form\FormBase;
use Drupal\image\ConfigurableImageEffectInterface;
use Drupal\image\ImageStyleInterface;
use Drupal\Component\Plugin\Exception\UnknownPluginException;
use Drupal\Component\Utility\String;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
......@@ -53,7 +55,12 @@ public function getFormID() {
*/
public function buildForm(array $form, array &$form_state, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
$this->imageStyle = $image_style;
$this->imageEffect = $this->prepareImageEffect($image_effect);
try {
$this->imageEffect = $this->prepareImageEffect($image_effect);
}
catch (UnknownPluginException $e) {
throw new NotFoundHttpException(String::format("Invalid effect id: '@id'.", array('@id' => $image_effect)));
}
$request = $this->getRequest();
if (!($this->imageEffect instanceof ConfigurableImageEffectInterface)) {
......
......@@ -315,8 +315,9 @@ function testStyleReplacement() {
*/
function testEditEffect() {
// Add a scale effect.
$style_name = 'test_style_effect_edit';
$this->drupalGet('admin/config/media/image-styles/add');
$this->drupalPostForm(NULL, array('label' => 'Test style effect edit', 'name' => 'test_style_effect_edit'), t('Create new style'));
$this->drupalPostForm(NULL, array('label' => 'Test style effect edit', 'name' => $style_name), t('Create new style'));
$this->drupalPostForm(NULL, array('new' => 'image_scale_and_crop'), t('Add'));
$this->drupalPostForm(NULL, array('data[width]' => '300', 'data[height]' => '200'), t('Add effect'));
$this->assertText(t('Scale and crop 300x200'));
......@@ -344,6 +345,11 @@ function testEditEffect() {
$this->drupalPostForm(NULL, array('data[width]' => '12', 'data[height]' => '19'), t('Add effect'));
$this->assertText(t('Scale 24x19'));
$this->assertText(t('Scale 12x19'));
// Try to edit a nonexistent effect.
$uuid = $this->container->get('uuid');
$this->drupalGet('admin/config/media/image-styles/manage/' . $style_name . '/effects/' . $uuid->generate());
$this->assertResponse(404);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment