Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / filter / src / Plugin / migrate / process / FilterSettings.php
1 <?php
2
3 namespace Drupal\filter\Plugin\migrate\process;
4
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
8
9 /**
10  * Adds the default allowed attributes to filter_html's allowed_html setting.
11  *
12  * E.g. map '<a>' to '<a href hreflang dir>'.
13  *
14  * @MigrateProcessPlugin(
15  *   id = "filter_settings",
16  *   handle_multiples = TRUE
17  * )
18  */
19 class FilterSettings extends ProcessPluginBase {
20
21   /**
22    * Default attributes for migrating filter_html's 'allowed_html' setting.
23    *
24    * @var string[]
25    */
26   protected $allowedHtmlDefaultAttributes = [
27     '<a>' => '<a href hreflang>',
28     '<blockquote>' => '<blockquote cite>',
29     '<ol>' => '<ol start type>',
30     '<ul>' => '<ul type>',
31     '<img>' => '<img src alt height width>',
32     '<h2>' => '<h2 id>',
33     '<h3>' => '<h3 id>',
34     '<h4>' => '<h4 id>',
35     '<h5>' => '<h5 id>',
36     '<h6>' => '<h6 id>',
37   ];
38
39   /**
40    * {@inheritdoc}
41    */
42   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
43     // Only the filter_html filter's settings have a changed format.
44     if ($row->getDestinationProperty('id') === 'filter_html') {
45       if (!empty($value['allowed_html'])) {
46         $value['allowed_html'] = str_replace(array_keys($this->allowedHtmlDefaultAttributes), array_values($this->allowedHtmlDefaultAttributes), $value['allowed_html']);
47       }
48     }
49     return $value;
50   }
51
52 }