FontSelectionImageEffect.php in Image Effects 8.2
File
tests/modules/image_effects_module_test/src/Plugin/ImageEffect/FontSelectionImageEffect.php
View source
<?php
namespace Drupal\image_effects_module_test\Plugin\ImageEffect;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Image\ImageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\image\ConfigurableImageEffectBase;
use Drupal\image_effects\Plugin\ImageEffectsFontSelectorPluginInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FontSelectionImageEffect extends ConfigurableImageEffectBase implements ContainerFactoryPluginInterface {
protected $fontSelector;
public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ImageEffectsFontSelectorPluginInterface $font_selector_plugin) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $logger);
$this->fontSelector = $font_selector_plugin;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('logger.factory')
->get('image'), $container
->get('plugin.manager.image_effects.font_selector')
->getPlugin());
}
public function defaultConfiguration() {
return [
'font_name' => '',
'font_uri' => '',
];
}
public function getSummary() {
return [
'#markup' => $this->configuration['font_name'],
] + parent::getSummary();
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$options = [
'#default_value' => $this->configuration['font_uri'],
];
$form['font_uri'] = $this->fontSelector
->selectionElement($options);
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['font_uri'] = $form_state
->getValue('font_uri');
$this->configuration['font_name'] = $this->fontSelector
->getDescription($form_state
->getValue('font_uri'));
}
public function applyEffect(ImageInterface $image) {
return TRUE;
}
}