Version 1
[yaffs-website] / web / core / modules / filter / src / Plugin / migrate / source / d7 / FilterFormat.php
1 <?php
2
3 namespace Drupal\filter\Plugin\migrate\source\d7;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Row;
7
8 /**
9  * Drupal 7 filter source from database.
10  *
11  * @MigrateSource(
12  *   id = "d7_filter_format"
13  * )
14  */
15 class FilterFormat extends DrupalSqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     return $this->select('filter_format', 'f')->fields('f');
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function fields() {
28     return [
29       'format' => $this->t('Format ID.'),
30       'name' => $this->t('The name of the format.'),
31       'cache' => $this->t('Whether the format is cacheable.'),
32       'status' => $this->t('The status of the format'),
33       'weight' => $this->t('The weight of the format'),
34       'filters' => $this->t('The filters configured for the format.'),
35     ];
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function prepareRow(Row $row) {
42     // Find filters for this format.
43     $filters = $this->select('filter', 'f')
44       ->fields('f')
45       ->condition('format', $row->getSourceProperty('format'))
46       ->condition('status', 1)
47       ->execute()
48       ->fetchAllAssoc('name');
49
50     foreach ($filters as $id => $filter) {
51       $filters[$id]['settings'] = unserialize($filter['settings']);
52     }
53     $row->setSourceProperty('filters', $filters);
54
55     return parent::prepareRow($row);
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getIds() {
62     $ids['format']['type'] = 'string';
63     return $ids;
64   }
65
66 }