Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / crop / src / Plugin / ImageEffect / CropEffect.php
index 99592959b085a17fa2be73ed0c06930dc68b080b..5f41e6b7d6e000fdf88af3a5665244502f7f1641 100644 (file)
@@ -160,7 +160,7 @@ class CropEffect extends ConfigurableImageEffectBase implements ContainerFactory
   /**
    * Gets crop entity for the image.
    *
-   * @param ImageInterface $image
+   * @param \Drupal\Core\Image\ImageInterface $image
    *   Image object.
    *
    * @return \Drupal\Core\Entity\EntityInterface|\Drupal\crop\CropInterface|false
@@ -181,11 +181,7 @@ class CropEffect extends ConfigurableImageEffectBase implements ContainerFactory
    * {@inheritdoc}
    */
   public function transformDimensions(array &$dimensions, $uri) {
-    /** @var \Drupal\Core\Image\Image $image */
-    $image = $this->imageFactory->get($uri);
-
-    /** @var \Drupal\crop\CropInterface $crop */
-    $crop = $this->getCrop($image);
+    $crop = Crop::findCrop($uri, $this->configuration['crop_type']);
     if (!$crop instanceof CropInterface) {
       return;
     }
@@ -196,4 +192,17 @@ class CropEffect extends ConfigurableImageEffectBase implements ContainerFactory
     $dimensions['height'] = $size['height'];
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function calculateDependencies() {
+    $dependencies = parent::calculateDependencies();
+
+    if (isset($this->configuration['crop_type']) && $crop_type = $this->typeStorage->load($this->configuration['crop_type'])) {
+      $dependencies[$crop_type->getConfigDependencyKey()] = [$crop_type->getConfigDependencyName()];
+    }
+
+    return $dependencies;
+  }
+
 }