Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / process / d7 / FieldInstanceDefaults.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\process\d7;
4
5 use Drupal\migrate\MigrateExecutableInterface;
6 use Drupal\migrate\ProcessPluginBase;
7 use Drupal\migrate\Row;
8
9 /**
10  * @MigrateProcessPlugin(
11  *   id = "d7_field_instance_defaults"
12  * )
13  */
14 class FieldInstanceDefaults extends ProcessPluginBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
20     list($default_value, $widget_settings) = $value;
21     $widget_type = $widget_settings['type'];
22     $default_value = $default_value ?: [];
23
24     // In Drupal 7, the default value for email fields is stored in the key
25     // 'email' while in Drupal 8 it is stored in the key 'value'.
26     if ($widget_type == 'email_textfield' && $default_value) {
27       $default_value[0]['value'] = $default_value[0]['email'];
28       unset($default_value[0]['email']);
29     }
30
31     return $default_value;
32   }
33
34 }