Version 1
[yaffs-website] / web / core / modules / image / src / Plugin / migrate / destination / EntityImageStyle.php
diff --git a/web/core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php b/web/core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php
new file mode 100644 (file)
index 0000000..3fc1e7f
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace Drupal\image\Plugin\migrate\destination;
+
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
+use Drupal\migrate\MigrateException;
+use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
+use Drupal\migrate\Row;
+
+/**
+ * Every migration that uses this destination must have an optional
+ * dependency on the d6_file migration to ensure it runs first.
+ *
+ * @MigrateDestination(
+ *   id = "entity:image_style"
+ * )
+ */
+class EntityImageStyle extends EntityConfigBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function import(Row $row, array $old_destination_id_values = []) {
+    $effects = [];
+
+    // Need to set the effects property to null on the row before the ImageStyle
+    // is created, this prevents improper effect plugin initialization.
+    if ($row->getDestinationProperty('effects')) {
+      $effects = $row->getDestinationProperty('effects');
+      $row->setDestinationProperty('effects', []);
+    }
+
+    /** @var \Drupal\Image\Entity\ImageStyle $style */
+    $style = $this->getEntity($row, $old_destination_id_values);
+
+    // Iterate the effects array so each effect plugin can be initialized.
+    // Catch any missing plugin exceptions.
+    foreach ($effects as $effect) {
+      try {
+        $style->addImageEffect($effect);
+      }
+      catch (PluginNotFoundException $e) {
+        throw new MigrateException($e->getMessage(), 0, $e);
+      }
+    }
+
+    $style->save();
+
+    return [$style->id()];
+  }
+
+}