From 068c9a5748adcd719d1f99729490691b81401048 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Mon, 12 Aug 2013 19:10:38 +0300 Subject: [PATCH] Issue #2063403 by claudiu.cristea: Fixed Crash when edit inexistent effect. --- core/lib/Drupal/Component/Plugin/DefaultPluginBag.php | 3 +++ core/lib/Drupal/Component/Plugin/PluginBag.php | 10 +++++++++- core/modules/image/image.module | 8 ++++++-- .../image/lib/Drupal/image/Form/ImageEffectFormBase.php | 3 +++ .../image/lib/Drupal/image/Tests/ImageAdminStylesTest.php | 9 ++++++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php index 9f9d566..8e64a88 100644 --- a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php +++ b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php @@ -65,6 +65,9 @@ public function __construct(PluginManagerInterface $manager, array $configuratio * {@inheritdoc} */ protected function initializePlugin($instance_id) { + if (!isset($this->configurations[$instance_id])) { + throw new PluginException(String::format("Unknown plugin ID '@instance'.", array('@instance' => $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))); diff --git a/core/lib/Drupal/Component/Plugin/PluginBag.php b/core/lib/Drupal/Component/Plugin/PluginBag.php index e37b367..3f77e03 100644 --- a/core/lib/Drupal/Component/Plugin/PluginBag.php +++ b/core/lib/Drupal/Component/Plugin/PluginBag.php @@ -7,6 +7,8 @@ namespace Drupal\Component\Plugin; +use Drupal\Component\Plugin\Exception\PluginException; + /** * Defines an object which stores multiple plugin instances to lazy load them. * @@ -65,7 +67,13 @@ public function has($instance_id) { */ public function &get($instance_id) { if (!isset($this->pluginInstances[$instance_id])) { - $this->initializePlugin($instance_id); + try { + $this->initializePlugin($instance_id); + } + catch (PluginException $e) { + $null = NULL; + return $null; + } } return $this->pluginInstances[$instance_id]; } diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 28b7bc2..5610303 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -72,8 +72,12 @@ 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])->getPluginDefinition(); - return isset($effect['description']) ? ('

' . $effect['description'] . '

') : NULL; + $effect = entity_load('image_style', $arg[5])->getEffect($arg[7]); + if (empty($effect)) { + return NULL; + } + $definition = $effect->getPluginDefinition(); + return isset($definition['description']) ? ('

' . $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 705dad3..dbfaf49 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php @@ -58,6 +58,9 @@ 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)) { + throw new NotFoundHttpException(); + } if (!($this->imageEffect instanceof ConfigurableImageEffectInterface)) { 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 6bcf733..78a5838 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -7,6 +7,7 @@ namespace Drupal\image\Tests; +use Drupal\Component\Uuid\Uuid; use Drupal\image\ImageStyleInterface; /** @@ -315,8 +316,9 @@ function testStyleReplacement() { */ function testEditEffect() { // Add a scale effect. + $style_name = 'test_style_effect_edit'; $this->drupalGet('admin/config/media/image-styles/add'); - $this->drupalPost(NULL, array('label' => 'Test style effect edit', 'name' => 'test_style_effect_edit'), t('Create new style')); + $this->drupalPost(NULL, array('label' => 'Test style effect edit', 'name' => $style_name), t('Create new style')); $this->drupalPost(NULL, array('new' => 'image_scale_and_crop'), t('Add')); $this->drupalPost(NULL, array('data[width]' => '300', 'data[height]' => '200'), t('Add effect')); $this->assertText(t('Scale and crop 300x200')); @@ -344,6 +346,11 @@ function testEditEffect() { $this->drupalPost(NULL, array('data[width]' => '12', 'data[height]' => '19'), t('Add effect')); $this->assertText(t('Scale 24x19')); $this->assertText(t('Scale 12x19')); + + // Try to edit an inexisting effect. + $uuid = new Uuid(); + $this->drupalGet('admin/config/media/image-styles/manage/' . $style_name . '/effects/' . $uuid->generate()); + $this->assertResponse(401); } /** -- 1.8.3.1