diff --git a/crop.module b/crop.module index 835924a..424692f 100644 --- a/crop.module +++ b/crop.module @@ -130,18 +130,26 @@ function crop_file_url_alter(&$uri) { // Get the file URI using parsed schema and file path. $file_uri = $match[2] . '://' . $match[3]; - /** @var \Drupal\image_widget_crop\ImageWidgetCropManager $image_widget_manager */ - $image_widget_manager = \Drupal::service('image_widget_crop.manager'); - /** @var \Drupal\image\Entity\ImageStyle $image_style */ $image_style = ImageStyle::load($image_style); + $crop_type = NULL; + // Find whether matched image style uses "crop_type" effect. + /* @var \Drupal\image\ImageEffectInterface $effect */ + foreach ($image_style->getEffects() as $uuid => $effect) { + $data_effect = $image_style->getEffect($uuid)->getConfiguration()['data']; + if (isset($data_effect['crop_type'])) { + $crop_type = $data_effect['crop_type']; + break; + } + } + // In case the image style uses "crop_type" effect, load the crop entity. - if ($crop = Crop::findCrop($file_uri, $image_widget_manager->getEffectData($image_style, 'crop_type'))) { - // Found a crop for this image, append an identifier for it to the URL, + if ($crop_type && $crop = Crop::findCrop($file_uri, $crop_type)) { + // Found a crop for this image, append a hash of it to the URL, // so that browsers reload the image and CDNs and proxies can be bypassed. - $query_string = implode($crop->position(), '-') . '-' . implode($crop->anchor(), '-'); - $uri .= '&v=' . $query_string; + $shortened_hash = substr(md5(implode($crop->position()) . implode($crop->anchor())), 0, 8); + $uri .= '&h=' . $shortened_hash; } } }