2fcf7d75966e930680bf273e2469f294a28ea8b8
[yaffs-website] / web / core / modules / language / src / Plugin / migrate / process / LanguageDomains.php
1 <?php
2
3 namespace Drupal\language\Plugin\migrate\process;
4
5 use Drupal\migrate\MigrateExecutableInterface;
6 use Drupal\migrate\Plugin\migrate\process\ArrayBuild;
7 use Drupal\migrate\Row;
8
9 /**
10  * This plugin makes sure that no domain is empty if domain negotiation is used.
11  *
12  * @MigrateProcessPlugin(
13  *   id = "language_domains",
14  *   handle_multiples = TRUE
15  * )
16  */
17 class LanguageDomains extends ArrayBuild {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
23     if ($row->getSourceProperty('domain_negotiation')) {
24       global $base_url;
25
26       foreach ($value as $old_key => $old_value) {
27         if (empty($old_value['domain'])) {
28           // The default language domain might be empty.
29           // If it is, use the current domain.
30           $value[$old_key]['domain'] = parse_url($base_url, PHP_URL_HOST);
31         }
32         else {
33           // Ensure we have a protocol when checking for the hostname.
34           $domain = 'http://' . str_replace(['http://', 'https://'], '', $old_value['domain']);
35           // Only keep the host part of the domain.
36           $value[$old_key]['domain'] = parse_url($domain, PHP_URL_HOST);
37         }
38       }
39     }
40
41     return parent::transform($value, $migrate_executable, $row, $destination_property);
42   }
43
44 }