1d91a3f7902ae0ebfc624f3b2e27afc8b39776da
[yaffs-website] / web / core / modules / datetime / src / Plugin / migrate / field / d6 / DateField.php
1 <?php
2
3 namespace Drupal\datetime\Plugin\migrate\field\d6;
4
5 @trigger_error('DateField is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\datetime\Plugin\migrate\field\DateField instead.', E_USER_DEPRECATED);
6
7 use Drupal\migrate\Plugin\MigrationInterface;
8 use Drupal\migrate\MigrateException;
9 use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
10
11 /**
12  * @MigrateField(
13  *   id = "date",
14  *   type_map = {
15  *     "date" = "datetime",
16  *     "datestamp" =  "timestamp",
17  *     "datetime" =  "datetime",
18  *   },
19  *   core = {6}
20  * )
21  *
22  * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
23  * \Drupal\datetime\Plugin\migrate\field\DateField instead.
24  */
25 class DateField extends FieldPluginBase {
26
27   /**
28    * {@inheritdoc}
29    */
30   public function getFieldWidgetMap() {
31     return [
32       'date' => 'datetime_default',
33       'datetime' => 'datetime_default',
34       'datestamp' => 'datetime_timestamp',
35     ];
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
42     switch ($data['type']) {
43       case 'date':
44         $from_format = 'Y-m-d\TH:i:s';
45         $to_format = 'Y-m-d\TH:i:s';
46         break;
47       case 'datestamp':
48         $from_format = 'U';
49         $to_format = 'U';
50         break;
51       case 'datetime':
52         $from_format = 'Y-m-d H:i:s';
53         $to_format = 'Y-m-d\TH:i:s';
54         break;
55       default:
56         throw new MigrateException(sprintf('Field %s of type %s is an unknown date field type.', $field_name, var_export($data['type'], TRUE)));
57     }
58     $process = [
59       'value' => [
60         'plugin' => 'format_date',
61         'from_format' => $from_format,
62         'to_format' => $to_format,
63         'source' => 'value',
64       ],
65     ];
66
67     $process = [
68       'plugin' => 'sub_process',
69       'source' => $field_name,
70       'process' => $process,
71     ];
72     $migration->mergeProcessOfProperty($field_name, $process);
73   }
74
75 }