MirrorImageEffect.php in Image Effects 8.3        
                          
                  
                        
  
  
  
  
File
  src/Plugin/ImageEffect/MirrorImageEffect.php
  
    View source  
  <?php
namespace Drupal\image_effects\Plugin\ImageEffect;
use Drupal\Core\Image\ImageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\image\ConfigurableImageEffectBase;
class MirrorImageEffect extends ConfigurableImageEffectBase {
  
  public function defaultConfiguration() {
    return [
      'x_axis' => FALSE,
      'y_axis' => FALSE,
    ] + parent::defaultConfiguration();
  }
  
  public function getSummary() {
    return [
      '#theme' => 'image_effects_mirror_summary',
      '#data' => $this->configuration,
    ] + parent::getSummary();
  }
  
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['x_axis'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Horizontal'),
      '#description' => $this
        ->t("If checked, the source image will be 'flopped' horizontally."),
      '#default_value' => $this->configuration['x_axis'],
    ];
    $form['y_axis'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Vertical'),
      '#description' => $this
        ->t("If checked, the source image will be 'flipped' vertically."),
      '#default_value' => $this->configuration['y_axis'],
    ];
    return $form;
  }
  
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::validateConfigurationForm($form, $form_state);
    $x_axis = (bool) $form_state
      ->getValue('x_axis');
    $y_axis = (bool) $form_state
      ->getValue('y_axis');
    if ($x_axis === FALSE && $y_axis === FALSE) {
      $form_state
        ->setError($form, $this
        ->t("Either an Horizontal or a Vertical mirroring must be selected."));
    }
  }
  
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    $this->configuration['x_axis'] = (bool) $form_state
      ->getValue('x_axis');
    $this->configuration['y_axis'] = (bool) $form_state
      ->getValue('y_axis');
  }
  
  public function applyEffect(ImageInterface $image) {
    return $image
      ->apply('mirror', [
      'x_axis' => $this->configuration['x_axis'],
      'y_axis' => $this->configuration['y_axis'],
    ]);
  }
}