Version 1
[yaffs-website] / web / core / modules / filter / src / Plugin / migrate / source / d6 / FilterFormat.php
1 <?php
2
3 namespace Drupal\filter\Plugin\migrate\source\d6;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Row;
7
8 /**
9  * Drupal 6 filter source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_filter_format"
13  * )
14  */
15 class FilterFormat extends DrupalSqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     return $this->select('filter_formats', '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       'roles' => $this->t('The role IDs which can use the format.'),
33       'filters' => $this->t('The filters configured for the format.'),
34     ];
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function prepareRow(Row $row) {
41     $filters = [];
42     $roles = $row->getSourceProperty('roles');
43     $row->setSourceProperty('roles', array_values(array_filter(explode(',', $roles))));
44     $format = $row->getSourceProperty('format');
45     // Find filters for this row.
46     $results = $this->select('filters', 'f')
47       ->fields('f', ['module', 'delta', 'weight'])
48       ->condition('format', $format)
49       ->execute();
50     foreach ($results as $raw_filter) {
51       $module = $raw_filter['module'];
52       $delta = $raw_filter['delta'];
53       $filter = [
54         'module' => $module,
55         'delta' => $delta,
56         'weight' => $raw_filter['weight'],
57         'settings' => [],
58       ];
59       // Load the filter settings for the filter module, modules can use
60       // hook_migration_d6_filter_formats_prepare_row() to add theirs.
61       if ($raw_filter['module'] == 'filter') {
62         if (!$delta) {
63           if ($setting = $this->variableGet("allowed_html_$format", NULL)) {
64             $filter['settings']['allowed_html'] = $setting;
65           }
66           if ($setting = $this->variableGet("filter_html_help_$format", NULL)) {
67             $filter['settings']['filter_html_help'] = $setting;
68           }
69           if ($setting = $this->variableGet("filter_html_nofollow_$format", NULL)) {
70             $filter['settings']['filter_html_nofollow'] = $setting;
71           }
72         }
73         elseif ($delta == 2 && ($setting = $this->variableGet("filter_url_length_$format", NULL))) {
74           $filter['settings']['filter_url_length'] = $setting;
75         }
76       }
77       $filters[] = $filter;
78     }
79
80     $row->setSourceProperty('filters', $filters);
81     return parent::prepareRow($row);
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public function getIds() {
88     $ids['format']['type'] = 'integer';
89     return $ids;
90   }
91
92 }