diff --git a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php index 8e64a88..ccffb4e 100644 --- a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php +++ b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php @@ -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. @@ -66,11 +65,11 @@ public function __construct(PluginManagerInterface $manager, array $configuratio */ protected function initializePlugin($instance_id) { if (!isset($this->configurations[$instance_id])) { - throw new PluginException(String::format("Unknown plugin ID '@instance'.", array('@instance' => $instance_id))); + throw new UnknownPluginException($instance_id); } $configuration = $this->configurations[$instance_id]; 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); diff --git a/core/lib/Drupal/Component/Plugin/Exception/UnknownPluginException.php b/core/lib/Drupal/Component/Plugin/Exception/UnknownPluginException.php new file mode 100644 index 0000000..6c8804f --- /dev/null +++ b/core/lib/Drupal/Component/Plugin/Exception/UnknownPluginException.php @@ -0,0 +1,31 @@ + $instance_id)); + } + parent::__construct($message, $code, $previous); + } + +} diff --git a/core/lib/Drupal/Component/Plugin/PluginBag.php b/core/lib/Drupal/Component/Plugin/PluginBag.php index 3f77e03..e37b367 100644 --- a/core/lib/Drupal/Component/Plugin/PluginBag.php +++ b/core/lib/Drupal/Component/Plugin/PluginBag.php @@ -7,8 +7,6 @@ namespace Drupal\Component\Plugin; -use Drupal\Component\Plugin\Exception\PluginException; - /** * Defines an object which stores multiple plugin instances to lazy load them. * @@ -67,13 +65,7 @@ public function has($instance_id) { */ public function &get($instance_id) { if (!isset($this->pluginInstances[$instance_id])) { - try { - $this->initializePlugin($instance_id); - } - catch (PluginException $e) { - $null = NULL; - return $null; - } + $this->initializePlugin($instance_id); } return $this->pluginInstances[$instance_id]; } diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 5610303..d22c658 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Component\Plugin\Exception\UnknownPluginException; use Drupal\field\Plugin\Core\Entity\Field; use Drupal\field\Plugin\Core\Entity\FieldInstance; use Drupal\file\Plugin\Core\Entity\File; @@ -72,12 +73,14 @@ function image_help($path, $arg) { $effect = Drupal::service('plugin.manager.image.effect')->getDefinition($arg[7]); return isset($effect['description']) ? ('

' . $effect['description'] . '

') : NULL; case 'admin/config/media/image-styles/manage/%/effects/%': - $effect = entity_load('image_style', $arg[5])->getEffect($arg[7]); - if (empty($effect)) { + try { + $effect = entity_load('image_style', $arg[5])->getEffect($arg[7]); + } + catch (UnknownPluginException $e) { return NULL; } - $definition = $effect->getPluginDefinition(); - return isset($definition['description']) ? ('

' . $definition['description'] . '

') : NULL; + $effect_definition = $effect->getPluginDefinition(); + return isset($effect_definition['description']) ? ('

' . $effect_definition['description'] . '

') : NULL; } } diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php index dbfaf49..d171e47 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormInterface; use Drupal\image\ConfigurableImageEffectInterface; use Drupal\image\ImageStyleInterface; +use Drupal\Component\Plugin\Exception\UnknownPluginException; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -57,8 +58,10 @@ public function getFormID() { */ public function buildForm(array $form, array &$form_state, Request $request = NULL, ImageStyleInterface $image_style = NULL, $image_effect = NULL) { $this->imageStyle = $image_style; - $this->imageEffect = $this->prepareImageEffect($image_effect); - if (empty($this->imageEffect)) { + try { + $this->imageEffect = $this->prepareImageEffect($image_effect); + } + catch (UnknownPluginException $e) { throw new NotFoundHttpException(); } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index 78a5838..e3aece9 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -347,10 +347,10 @@ function testEditEffect() { $this->assertText(t('Scale 24x19')); $this->assertText(t('Scale 12x19')); - // Try to edit an inexisting effect. + // Try to edit a nonexistent effect. $uuid = new Uuid(); $this->drupalGet('admin/config/media/image-styles/manage/' . $style_name . '/effects/' . $uuid->generate()); - $this->assertResponse(401); + $this->assertResponse(404); } /**