ImageStyleWithPipeline.php in Image Optimize (or ImageAPI Optimize) 8.2
File
src/Entity/ImageStyleWithPipeline.php
View source
<?php
namespace Drupal\imageapi_optimize\Entity;
use Drupal\image\Entity\ImageStyle;
class ImageStyleWithPipeline extends ImageStyle {
protected $pipeline = '__default__';
public function createDerivative($original_uri, $derivative_uri) {
$result = parent::createDerivative($original_uri, $derivative_uri);
if ($result) {
if ($this
->hasPipeline()) {
$this
->getPipelineEntity()
->applyToImage($derivative_uri);
}
}
return $result;
}
public function getPipeline() {
return $this->pipeline;
}
public function getPipelineEntity() {
if (!empty($this->pipeline)) {
$storage = $this
->entityTypeManager()
->getStorage('imageapi_optimize_pipeline');
if ($this->pipeline == '__default__') {
if ($default_pipeline_name = \Drupal::config('imageapi_optimize.settings')
->get('default_pipeline')) {
$pipelineId = $default_pipeline_name;
}
}
else {
$pipelineId = $this->pipeline;
}
if (!empty($pipelineId) && ($pipeline = $storage
->load($pipelineId))) {
return $pipeline;
}
}
}
public function hasPipeline() {
return (bool) $this
->getPipelineEntity();
}
}