Security update for Core, with self-updated composer
[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  *   source_module = "filter"
14  * )
15  */
16 class FilterFormat extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     return $this->select('filter_formats', 'f')->fields('f');
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public function fields() {
29     return [
30       'format' => $this->t('Format ID.'),
31       'name' => $this->t('The name of the format.'),
32       'cache' => $this->t('Whether the format is cacheable.'),
33       'roles' => $this->t('The role IDs which can use 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     $filters = [];
43     $roles = $row->getSourceProperty('roles');
44     $row->setSourceProperty('roles', array_values(array_filter(explode(',', $roles))));
45     $format = $row->getSourceProperty('format');
46     // Find filters for this row.
47     $results = $this->select('filters', 'f')
48       ->fields('f', ['module', 'delta', 'weight'])
49       ->condition('format', $format)
50       ->execute();
51     foreach ($results as $raw_filter) {
52       $module = $raw_filter['module'];
53       $delta = $raw_filter['delta'];
54       $filter = [
55         'module' => $module,
56         'delta' => $delta,
57         'weight' => $raw_filter['weight'],
58         'settings' => [],
59       ];
60       // Load the filter settings for the filter module, modules can use
61       // hook_migration_d6_filter_formats_prepare_row() to add theirs.
62       if ($raw_filter['module'] == 'filter') {
63         if (!$delta) {
64           if ($setting = $this->variableGet("allowed_html_$format", NULL)) {
65             $filter['settings']['allowed_html'] = $setting;
66           }
67           if ($setting = $this->variableGet("filter_html_help_$format", NULL)) {
68             $filter['settings']['filter_html_help'] = $setting;
69           }
70           if ($setting = $this->variableGet("filter_html_nofollow_$format", NULL)) {
71             $filter['settings']['filter_html_nofollow'] = $setting;
72           }
73         }
74         elseif ($delta == 2 && ($setting = $this->variableGet("filter_url_length_$format", NULL))) {
75           $filter['settings']['filter_url_length'] = $setting;
76         }
77       }
78       $filters[] = $filter;
79     }
80
81     $row->setSourceProperty('filters', $filters);
82     return parent::prepareRow($row);
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function getIds() {
89     $ids['format']['type'] = 'integer';
90     return $ids;
91   }
92
93 }