Version 1
[yaffs-website] / web / core / modules / image / src / Plugin / migrate / destination / EntityImageStyle.php
1 <?php
2
3 namespace Drupal\image\Plugin\migrate\destination;
4
5 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
6 use Drupal\migrate\MigrateException;
7 use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
8 use Drupal\migrate\Row;
9
10 /**
11  * Every migration that uses this destination must have an optional
12  * dependency on the d6_file migration to ensure it runs first.
13  *
14  * @MigrateDestination(
15  *   id = "entity:image_style"
16  * )
17  */
18 class EntityImageStyle extends EntityConfigBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function import(Row $row, array $old_destination_id_values = []) {
24     $effects = [];
25
26     // Need to set the effects property to null on the row before the ImageStyle
27     // is created, this prevents improper effect plugin initialization.
28     if ($row->getDestinationProperty('effects')) {
29       $effects = $row->getDestinationProperty('effects');
30       $row->setDestinationProperty('effects', []);
31     }
32
33     /** @var \Drupal\Image\Entity\ImageStyle $style */
34     $style = $this->getEntity($row, $old_destination_id_values);
35
36     // Iterate the effects array so each effect plugin can be initialized.
37     // Catch any missing plugin exceptions.
38     foreach ($effects as $effect) {
39       try {
40         $style->addImageEffect($effect);
41       }
42       catch (PluginNotFoundException $e) {
43         throw new MigrateException($e->getMessage(), 0, $e);
44       }
45     }
46
47     $style->save();
48
49     return [$style->id()];
50   }
51
52 }