Completed
Pull Request — master (#157)
by
unknown
12:36
created

DatetimeDrupal8::processValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Drupal\Driver\Plugin\DriverField;
4
5
use Drupal\Driver\Plugin\DriverFieldPluginDrupal8Base;
6
7
/**
8
 * A driver field plugin for datetime fields.
9
 *
10
 * @DriverField(
11
 *   id = "datetime",
12
 *   version = 8,
13
 *   fieldTypes = {
14
 *     "datetime",
15
 *   },
16
 *   weight = -100,
17
 * )
18
 */
19
class DatetimeDrupal8 extends DriverFieldPluginDrupal8Base {
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  protected function processValue($value) {
25
    if (strpos($value['value'], "relative:") !== FALSE) {
26
      $relative = trim(str_replace('relative:', '', $value['value']));
27
      // Get time, convert to ISO 8601 date in GMT/UTC, remove TZ offset.
28
      $processedValue = substr(gmdate('c', strtotime($relative)), 0, 19);
29
    }
30
    else {
31
      $processedValue = str_replace(' ', 'T', $value['value']);
32
    }
33
    return ['value' => $processedValue];
34
  }
35
36
}
37