Version 1
[yaffs-website] / web / core / modules / image / src / Plugin / migrate / process / d6 / ImageCacheActions.php
1 <?php
2
3 namespace Drupal\image\Plugin\migrate\process\d6;
4
5 use Drupal\migrate\MigrateExecutableInterface;
6 use Drupal\migrate\ProcessPluginBase;
7 use Drupal\migrate\Row;
8
9 /**
10  * @MigrateProcessPlugin(
11  *   id = "d6_imagecache_actions"
12  * )
13  */
14 class ImageCacheActions extends ProcessPluginBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
20     $effects = [];
21
22     foreach ($row->getSourceProperty('actions') as $action) {
23       $id = preg_replace('/^imagecache/', 'image', $action['action']);
24
25       if ($id === 'image_crop') {
26         $action['data']['anchor'] = $action['data']['xoffset'] . '-' . $action['data']['yoffset'];
27
28         if (!preg_match('/^[a-z]*\-[a-z]*/', $action['data']['anchor'])) {
29           $migrate_executable->message->display(
30             'The Drupal 8 image crop effect does not support numeric values for x and y offsets. Use keywords to set crop effect offsets instead.',
31             'error'
32           );
33         }
34
35         unset($action['data']['xoffset']);
36         unset($action['data']['yoffset']);
37       }
38
39       $effects[] = [
40         'id'     => $id,
41         'weight' => $action['weight'],
42         'data'   => $action['data'],
43       ];
44     }
45
46     return $effects;
47   }
48
49 }