mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 01:34:31 +02:00
Add PR #124 - Add hookable method to PageImage variation creation
Co-authored-by: karltdev <karl@assembly.com.hk>
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
* @method array rebuildVariations($mode = 0, array $suffix = array(), array $options = array())
|
||||
* @method install($filename)
|
||||
* @method render($markup = '', $options = array())
|
||||
* @method void createdVariation(Pageimage $image, array $data) Called after new image variation created (3.0.180+)
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -745,6 +746,7 @@ class Pageimage extends Pagefile {
|
||||
$debug = $config->debug;
|
||||
$configOptions = $config->imageSizerOptions;
|
||||
$webpOptions = $config->webpOptions;
|
||||
$createdVariationHookData = null; // populated as array only when new variation created (for createdVariation hook)
|
||||
if(!empty($webpOptions['quality'])) $defaultOptions['webpQuality'] = $webpOptions['quality'];
|
||||
|
||||
if(!is_array($configOptions)) $configOptions = array();
|
||||
@@ -916,6 +918,18 @@ class Pageimage extends Pagefile {
|
||||
"(quality=$options[quality], sharpening=$options[sharpening]) "
|
||||
);
|
||||
|
||||
if(!$this->error) {
|
||||
$createdVariationHookData = array(
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'options' => $options,
|
||||
'filenameUnvalidated' => $filenameUnvalidated,
|
||||
'filenameFinal' => $filenameFinal,
|
||||
'filenameUnvalidatedWebp' => $filenameUnvalidatedWebp,
|
||||
'filenameFinalWebp' => $filenameFinalWebp,
|
||||
);
|
||||
}
|
||||
|
||||
} catch(\Exception $e) {
|
||||
$this->trackException($e, false);
|
||||
$this->error = $e->getMessage();
|
||||
@@ -945,6 +959,8 @@ class Pageimage extends Pagefile {
|
||||
$pageimage->setFilename($filenameFinal);
|
||||
$pageimage->setOriginal($this);
|
||||
|
||||
if($createdVariationHookData) $this->createdVariation($pageimage, $createdVariationHookData);
|
||||
|
||||
return $pageimage;
|
||||
}
|
||||
|
||||
@@ -1426,6 +1442,16 @@ class Pageimage extends Pagefile {
|
||||
return $this->variations()->remove($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after successful creation of image variation
|
||||
*
|
||||
* @param Pageimage $image The variation image that was created
|
||||
* @param array $data Verbose associative array of data used to create the variation
|
||||
* @since 3.0.180
|
||||
*
|
||||
*/
|
||||
protected function ___createdVariation(Pageimage $image, array $data) { }
|
||||
|
||||
/**
|
||||
* Identify this Pageimage as a variation, by setting the Pageimage it was resized from.
|
||||
*
|
||||
|
Reference in New Issue
Block a user