Skip to content
Snippets Groups Projects

Issue #2969731 by sleitner: Support node fields Creation time and Changed time

Merged sleitner requested to merge issue/date_pager-2969731:2969731-support-node-fields into 2.1.x
2 files
+ 47
5
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -36,6 +36,8 @@ class DatePager extends PagerPluginBase implements CacheableDependencyInterface
* @var string[]
*/
protected $supportedDateTypes = [
'changed',
'created',
'datetime',
'daterange',
'smartdate',
@@ -166,7 +168,7 @@ class DatePager extends PagerPluginBase implements CacheableDependencyInterface
}
if ($field_storage->isBaseField()) {
$this->fieldTable = $this->entityTypeManager->getStorage($entity_type)
->getBaseTable();
->getDataTable();
}
else {
$this->fieldTable = $table_mapping->getDedicatedDataTableName($field_storage);
@@ -278,12 +280,14 @@ class DatePager extends PagerPluginBase implements CacheableDependencyInterface
if ($storage_definitions[$field_name]) {
$identifier = "{$base_entity_type_id}.{$field_name}";
$date_fields[$identifier] = "";
$all_fields = [];
foreach ($field['bundles'] as $bundle) {
$bundle_fields = $this->entityFieldManager->getFieldDefinitions($base_entity_type_id, $bundle);
// This can get very long.
// @todo Find a nicer way to list a lot of bundles.
$date_fields[$identifier] .= $bundle_fields[$field_name]->getLabel() . " ($bundle)";
$all_fields[] = $bundle_fields[$field_name]->getLabel() . " ($bundle)";
}
$date_fields[$identifier] = implode(', ', $all_fields);
}
}
}
@@ -371,12 +375,17 @@ class DatePager extends PagerPluginBase implements CacheableDependencyInterface
break;
}
// With smartdate timestamps need to be converted to datetime.
if ($this->dateFieldType === 'smartdate') {
if (in_array($this->dateFieldType, ['created', 'changed', 'smartdate'])) {
$start_date = strtotime($start_date);
$end_date = strtotime($end_date);
}
$this->view->query->addWhere(1, $value_column, $end_date, '<=');
$this->view->query->addWhere(1, $end_column, $start_date, '>=');
if (in_array($this->dateFieldType, ['created', 'changed'])) {
$this->view->query->addWhere(1, $value_column, $start_date, '>=');
}
else {
$this->view->query->addWhere(1, $end_column, $start_date, '>=');
}
}
}
}
@@ -410,7 +419,7 @@ class DatePager extends PagerPluginBase implements CacheableDependencyInterface
$max_date = $range['max'];
// With smartdate timestamps need to be converted to datetime.
if ($this->dateFieldType === 'smartdate') {
if (in_array($this->dateFieldType, ['smartdate', 'created', 'changed'])) {
$min_date = date($this->dateFormatString, $range['min']);
$max_date = date($this->dateFormatString, $range['max']);
}
Loading