Version 1
[yaffs-website] / web / core / modules / image / src / Plugin / migrate / source / d7 / ImageStyles.php
1 <?php
2
3 namespace Drupal\image\Plugin\migrate\source\d7;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Row;
7
8 /**
9  * Drupal image styles source from database.
10  *
11  * @MigrateSource(
12  *   id = "d7_image_styles",
13  *   source_provider = "image"
14  * )
15  */
16 class ImageStyles extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     return $this->select('image_styles', 'ims')
23       ->fields('ims');
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   public function fields() {
30     $fields = [
31       'isid' => $this->t('The primary identifier for an image style.'),
32       'name' => $this->t('The style machine name.'),
33       'label' => $this->t('The style administrative name.'),
34     ];
35     return $fields;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getIds() {
42     $ids['isid']['type'] = 'integer';
43     return $ids;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function prepareRow(Row $row) {
50     $effects = [];
51
52     $results = $this->select('image_effects', 'ie')
53       ->fields('ie')
54       ->condition('isid', $row->getSourceProperty('isid'))
55       ->execute();
56
57     foreach ($results as $key => $result) {
58       $result['data'] = unserialize($result['data']);
59       $effects[$key] = $result;
60     }
61
62     $row->setSourceProperty('effects', $effects);
63     return parent::prepareRow($row);
64   }
65
66 }