I'm trying to port an image effect from D7 to D8.

I've got Drupal to list the plugin, but when I try to use it I get a WSOD with "Fatal error: Cannot redeclare class Drupal\image\Plugin\ImageEffect\EffectMagic".

I've checked and there is no other declaration of this class anywhere.

My file is in mymod/src/Plugin/ImageEffect/EffectMagic.php and it looks like this (nb. content of functions is removed)

 * @file
 * Contains \Drupal\image\Plugin\ImageEffect\EffectMagic.

namespace Drupal\image\Plugin\ImageEffect;

use Drupal\Core\Image\ImageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\image\ConfigurableImageEffectBase;

 * Scales and crops an image resource.
 * @ImageEffect(
 *   id = "image_effect_magic",
 *   label = @Translation("Effect Magic"),
 *   description = @Translation("Use ImageMagic command line to process images.")
 * )
class EffectMagic extends ConfigurableImageEffectBase {
  public function buildConfigurationForm(array $form, FormStateInterface $form_state)
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state)
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
  public function applyEffect(ImageInterface $image)
  public function transformDimensions(array &$dimensions, $uri)
  public function getSummary()
  public function defaultConfiguration()
  • 1
    I am not sure if is the cause of the problem, but I am pretty sure your module should define it's own namespace, not use the same namespace as the image module: namespace Drupal\mymod\Plugin\ImageEffect; Mar 15 '16 at 18:18
  • Took me some long days to figure things out as well ;) Mar 15 '16 at 18:31
  • 1
    @Neograph734 That would make a good answer if you have time to put it in :)
    – Clive
    Mar 15 '16 at 18:34
  • Give me a second to write a detailed answer :) Mar 15 '16 at 18:37

When you are creating a custom module, you have to make sure your module registers its own namespace. In the current situation your module is attempting to use the namespace of the image module namespace Drupal\image\Plugin\ImageEffect;. Where you should actually be using a namespace of your own module namespace Drupal\mymod\Plugin\ImageEffect;

Then if you require functions of the image module, you can (as you have done already) load the other classes and functions with use. Like use Drupal\image\ConfigurableImageEffectBase;.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.