devel_wizard-2.x-dev/templates/spell/image_effect/class.php.twig
templates/spell/image_effect/class.php.twig
<?php
declare(strict_types=1);
namespace {{ imageEffect.classNamespace }};
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Image\ImageInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\image\Attribute\ImageEffect;
use Drupal\image\ConfigurableImageEffectBase;
#[ImageEffect(
id: '{{ imageEffect.id }}',
label: new TranslatableMarkup('{{ imageEffect.label }}'),
description: new TranslatableMarkup('{{ imageEffect.description }}'),
)]
class {{ imageEffect.className }} extends ConfigurableImageEffectBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration(): array {
$defaults = parent::defaultConfiguration();
$defaults['foo'] = 0;
return $defaults;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
$form['help'] = [
'#value' => $this->t('{{ imageEffect.description }}'),
];
$form['foo'] = [
'#type' => 'number',
'#title' => $this->t('Foo'),
'#description' => $this->t('@todo Real description.'),
'#required' => TRUE,
'#default_value' => $this->configuration['foo'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['foo'] = $form_state->getValue('foo');
}
/**
* {@inheritdoc}
*/
public function getSummary(): array {
$summary = [
'#theme' => '{{ summary.theme }}',
'#data' => $this->configuration,
];
return $summary + parent::getSummary();
}
/**
* {@inheritdoc}
*/
public function applyEffect(ImageInterface $image): bool {
if (!$image->apply('{{ imageEffect.idShort }}', $this->configuration)) {
$this->logger->error(
'Image effect %effect failed using the %toolkit toolkit on %path (%mimetype)',
[
'%effect' => $this->label(),
'%toolkit' => $image->getToolkitId(),
'%path' => $image->getSource(),
'%mimetype' => $image->getMimeType(),
],
);
return FALSE;
}
return TRUE;
}
}
