3 namespace Drupal\language\Plugin\migrate\process;
5 use Drupal\migrate\MigrateExecutableInterface;
6 use Drupal\migrate\Plugin\migrate\process\ArrayBuild;
7 use Drupal\migrate\Row;
10 * This plugin makes sure that no domain is empty if domain negotiation is used.
12 * @MigrateProcessPlugin(
13 * id = "language_domains",
14 * handle_multiples = TRUE
17 class LanguageDomains extends ArrayBuild {
22 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
23 if ($row->getSourceProperty('domain_negotiation')) {
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);
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);
41 return parent::transform($value, $migrate_executable, $row, $destination_property);