You are here

trait ReplaceImageTrait in Image Effects 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/ReplaceImageTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\ReplaceImageTrait
  2. 8 src/Plugin/ImageToolkit/Operation/ReplaceImageTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\ReplaceImageTrait

Base trait for replace image operations.

Hierarchy

2 files declare their use of ReplaceImageTrait
ReplaceImage.php in src/Plugin/ImageToolkit/Operation/gd/ReplaceImage.php
ReplaceImage.php in src/Plugin/ImageToolkit/Operation/imagemagick/ReplaceImage.php

File

src/Plugin/ImageToolkit/Operation/ReplaceImageTrait.php, line 10

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation
View source
trait ReplaceImageTrait {

  /**
   * {@inheritdoc}
   */
  protected function arguments() {
    return [
      'replacement_image' => [
        'description' => 'The image to be used to replace current one.',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function validateArguments(array $arguments) {

    // Ensure replacement_image is an expected ImageInterface object.
    if (!$arguments['replacement_image'] instanceof ImageInterface) {
      throw new \InvalidArgumentException("Replacement image passed to the 'replace_image' operation is invalid");
    }

    // Ensure replacement_image is a valid image.
    if (!$arguments['replacement_image']
      ->isValid()) {
      $source = $arguments['replacement_image']
        ->getSource();
      throw new \InvalidArgumentException("Invalid image at {$source}");
    }
    return $arguments;
  }

}

Members