Issue #3095146 by Wim Leers, heddn: Drupal 7 date fields configured to not collect the hour/minute/second granularities can have a different "settings" structure than the migration assumes
parent
802719a568
commit
347624ad75
|
@ -53,11 +53,10 @@ class DateField extends FieldPluginBase {
|
|||
$field_data = unserialize($data['field_definition']['data']);
|
||||
if (isset($field_data['settings']['granularity'])) {
|
||||
$granularity = $field_data['settings']['granularity'];
|
||||
if ($granularity = $field_data['settings']['granularity'] &&
|
||||
$granularity['hour'] === 0 &&
|
||||
$granularity['minute'] === 0 &&
|
||||
$granularity['second'] === 0) {
|
||||
|
||||
$collected_date_attributes = is_numeric(array_keys($granularity)[0])
|
||||
? $granularity
|
||||
: array_keys(array_filter($granularity));
|
||||
if (empty(array_intersect($collected_date_attributes, ['hour', 'minute', 'second']))) {
|
||||
$to_format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,23 @@ class DateFieldTest extends UnitTestCase {
|
|||
'Y-m-d H:i:s',
|
||||
'Y-m-d',
|
||||
],
|
||||
[
|
||||
[
|
||||
'type' => 'date',
|
||||
'field_definition' => [
|
||||
'data' => serialize([
|
||||
'settings' => [
|
||||
'granularity' => [
|
||||
0 => 'year',
|
||||
1 => 'month',
|
||||
],
|
||||
],
|
||||
]),
|
||||
],
|
||||
],
|
||||
'Y-m-d\TH:i:s',
|
||||
'Y-m-d',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,10 @@ class FieldSettings extends ProcessPluginBase {
|
|||
case 'date':
|
||||
case 'datetime':
|
||||
case 'datestamp':
|
||||
if ($value['granularity']['hour'] === 0
|
||||
&& $value['granularity']['minute'] === 0
|
||||
&& $value['granularity']['second'] === 0) {
|
||||
$collected_date_attributes = is_numeric(array_keys($value['granularity'])[0])
|
||||
? $value['granularity']
|
||||
: array_keys(array_filter($value['granularity']));
|
||||
if (empty(array_intersect($collected_date_attributes, ['hour', 'minute', 'second']))) {
|
||||
$value['datetime_type'] = 'date';
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue