updated core to 8.6.1 via composer
This commit is contained in:
@@ -5,4 +5,4 @@ package: Field types
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- field
|
||||
- drupal:field
|
||||
|
||||
@@ -11,18 +11,42 @@ use Drupal\field\FieldStorageConfigInterface;
|
||||
* Implements hook_field_views_data().
|
||||
*/
|
||||
function datetime_field_views_data(FieldStorageConfigInterface $field_storage) {
|
||||
return datetime_type_field_views_data_helper($field_storage, [], $field_storage->getMainPropertyName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides Views integration for any datetime-based fields.
|
||||
*
|
||||
* Overrides the default Views data for datetime-based fields, adding datetime
|
||||
* views plugins. Modules defining new datetime-based fields may use this
|
||||
* function to simplify Views integration.
|
||||
*
|
||||
* @param \Drupal\field\FieldStorageConfigInterface $field_storage
|
||||
* The field storage config entity.
|
||||
* @param array $data
|
||||
* Field view data or views_field_default_views_data($field_storage) if empty.
|
||||
* @param string $column_name
|
||||
* The schema column name with the datetime value.
|
||||
*
|
||||
* @return array
|
||||
* The array of field views data with the datetime plugin.
|
||||
*
|
||||
* @see datetime_field_views_data()
|
||||
* @see datetime_range_field_views_data()
|
||||
*/
|
||||
function datetime_type_field_views_data_helper(FieldStorageConfigInterface $field_storage, array $data, $column_name) {
|
||||
// @todo This code only covers configurable fields, handle base table fields
|
||||
// in https://www.drupal.org/node/2489476.
|
||||
$data = views_field_default_views_data($field_storage);
|
||||
$data = empty($data) ? views_field_default_views_data($field_storage) : $data;
|
||||
foreach ($data as $table_name => $table_data) {
|
||||
// Set the 'datetime' filter type.
|
||||
$data[$table_name][$field_storage->getName() . '_value']['filter']['id'] = 'datetime';
|
||||
$data[$table_name][$field_storage->getName() . '_' . $column_name]['filter']['id'] = 'datetime';
|
||||
|
||||
// Set the 'datetime' argument type.
|
||||
$data[$table_name][$field_storage->getName() . '_value']['argument']['id'] = 'datetime';
|
||||
$data[$table_name][$field_storage->getName() . '_' . $column_name]['argument']['id'] = 'datetime';
|
||||
|
||||
// Create year, month, and day arguments.
|
||||
$group = $data[$table_name][$field_storage->getName() . '_value']['group'];
|
||||
$group = $data[$table_name][$field_storage->getName() . '_' . $column_name]['group'];
|
||||
$arguments = [
|
||||
// Argument type => help text.
|
||||
'year' => t('Date in the form of YYYY.'),
|
||||
@@ -33,11 +57,16 @@ function datetime_field_views_data(FieldStorageConfigInterface $field_storage) {
|
||||
'full_date' => t('Date in the form of CCYYMMDD.'),
|
||||
];
|
||||
foreach ($arguments as $argument_type => $help_text) {
|
||||
$data[$table_name][$field_storage->getName() . '_value_' . $argument_type] = [
|
||||
'title' => $field_storage->getLabel() . ' (' . $argument_type . ')',
|
||||
$column_name_text = $column_name === $field_storage->getMainPropertyName() ? '' : ':' . $column_name;
|
||||
$data[$table_name][$field_storage->getName() . '_' . $column_name . '_' . $argument_type] = [
|
||||
'title' => t('@label@column (@argument)', [
|
||||
'@label' => $field_storage->getLabel(),
|
||||
'@column' => $column_name_text,
|
||||
'@argument' => $argument_type,
|
||||
]),
|
||||
'help' => $help_text,
|
||||
'argument' => [
|
||||
'field' => $field_storage->getName() . '_value',
|
||||
'field' => $field_storage->getName() . '_' . $column_name,
|
||||
'id' => 'datetime_' . $argument_type,
|
||||
'entity_type' => $field_storage->getTargetEntityTypeId(),
|
||||
'field_name' => $field_storage->getName(),
|
||||
@@ -47,7 +76,7 @@ function datetime_field_views_data(FieldStorageConfigInterface $field_storage) {
|
||||
}
|
||||
|
||||
// Set the 'datetime' sort handler.
|
||||
$data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime';
|
||||
$data[$table_name][$field_storage->getName() . '_' . $column_name]['sort']['id'] = 'datetime';
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
@@ -182,13 +182,13 @@ class DateTimeTimeAgoFormatter extends FormatterBase implements ContainerFactory
|
||||
if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
|
||||
$result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
|
||||
$build = [
|
||||
'#markup' => SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $result->getString()]),
|
||||
'#markup' => new FormattableMarkup($this->getSetting('past_format'), ['@interval' => $result->getString()]),
|
||||
];
|
||||
}
|
||||
else {
|
||||
$result = $this->dateFormatter->formatTimeDiffUntil($timestamp, $options);
|
||||
$build = [
|
||||
'#markup' => SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $result->getString()]),
|
||||
'#markup' => new FormattableMarkup($this->getSetting('future_format'), ['@interval' => $result->getString()]),
|
||||
];
|
||||
}
|
||||
CacheableMetadata::createFromObject($result)->applyTo($build);
|
||||
|
||||
@@ -51,9 +51,9 @@ class DateTimeFieldItemList extends FieldItemList {
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[id="edit-default-value-input-default-date-type"]' => ['value' => static::DEFAULT_VALUE_CUSTOM],
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $element;
|
||||
@@ -112,7 +112,7 @@ class DateTimeFieldItemList extends FieldItemList {
|
||||
[
|
||||
'value' => $value,
|
||||
'date' => $date,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
return $default_value;
|
||||
|
||||
@@ -44,7 +44,7 @@ class DateField extends FieldPluginBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
|
||||
switch ($data['type']) {
|
||||
case 'date':
|
||||
$from_format = 'Y-m-d\TH:i:s';
|
||||
|
||||
@@ -40,7 +40,7 @@ class DateField extends FieldPluginBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
|
||||
switch ($data['type']) {
|
||||
case 'date':
|
||||
$from_format = 'Y-m-d\TH:i:s';
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\datetime\Tests;
|
||||
|
||||
@trigger_error('\Drupal\datetime\Tests\DateTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\BrowserTestBase instead. See https://www.drupal.org/node/2780063.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
|
||||
@@ -111,7 +110,7 @@ abstract class DateTestBase extends WebTestBase {
|
||||
* Creates a date test field.
|
||||
*/
|
||||
protected function createField() {
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$type = $this->getTestFieldType();
|
||||
$widget_type = $formatter_type = $type . '_default';
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ abstract class DateTimeHandlerTestBase extends HandlerTestBase {
|
||||
// Add a date field to page nodes.
|
||||
$node_type = NodeType::create([
|
||||
'type' => 'page',
|
||||
'name' => 'page'
|
||||
'name' => 'page',
|
||||
]);
|
||||
$node_type->save();
|
||||
$fieldStorage = FieldStorageConfig::create([
|
||||
|
||||
@@ -5,4 +5,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- views
|
||||
- drupal:views
|
||||
|
||||
@@ -106,8 +106,8 @@ abstract class DateTestBase extends BrowserTestBase {
|
||||
* Creates a date test field.
|
||||
*/
|
||||
protected function createField() {
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_label = Unicode::ucfirst(Unicode::strtolower($this->randomMachineName()));
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_label = Unicode::ucfirst(mb_strtolower($this->randomMachineName()));
|
||||
$type = $this->getTestFieldType();
|
||||
$widget_type = $formatter_type = $type . '_default';
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace Drupal\Tests\datetime\Functional;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Datetime\Entity\DateFormat;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
|
||||
@@ -190,8 +188,8 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
|
||||
->setComponent($field_name, $this->displayOptions)
|
||||
->save();
|
||||
$expected = SafeMarkup::format($this->displayOptions['settings']['past_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']])
|
||||
$expected = new FormattableMarkup($this->displayOptions['settings']['past_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
|
||||
]);
|
||||
$output = $this->renderTestEntity($id);
|
||||
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
|
||||
@@ -214,8 +212,8 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
|
||||
->setComponent($field_name, $this->displayOptions)
|
||||
->save();
|
||||
$expected = SafeMarkup::format($this->displayOptions['settings']['future_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']])
|
||||
$expected = new FormattableMarkup($this->displayOptions['settings']['future_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
|
||||
]);
|
||||
$output = $this->renderTestEntity($id);
|
||||
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
|
||||
@@ -285,7 +283,7 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
$expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC');
|
||||
$output = $this->renderTestEntity($id);
|
||||
$expected_markup = '<time datetime="' . $expected_iso . '" class="datetime">' . $expected . '</time>';
|
||||
$this->assertContains($expected_markup, $output, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso]));
|
||||
$this->assertContains($expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -299,7 +297,7 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
->save();
|
||||
$expected = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
|
||||
$output = $this->renderTestEntity($id);
|
||||
$this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
|
||||
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
|
||||
|
||||
// Verify that the 'datetime_custom' formatter works.
|
||||
$this->displayOptions['type'] = 'datetime_custom';
|
||||
@@ -309,7 +307,7 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
->save();
|
||||
$expected = $date->format($this->displayOptions['settings']['date_format']);
|
||||
$output = $this->renderTestEntity($id);
|
||||
$this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));
|
||||
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));
|
||||
|
||||
// Verify that the 'timezone_override' setting works.
|
||||
$this->displayOptions['type'] = 'datetime_custom';
|
||||
@@ -319,7 +317,7 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
->save();
|
||||
$expected = $date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']);
|
||||
$output = $this->renderTestEntity($id);
|
||||
$this->assertContains($expected, $output, SafeMarkup::format('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));
|
||||
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));
|
||||
|
||||
// Verify that the 'datetime_time_ago' formatter works for intervals in the
|
||||
// past. First update the test entity so that the date difference always
|
||||
@@ -342,11 +340,11 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
|
||||
->setComponent($field_name, $this->displayOptions)
|
||||
->save();
|
||||
$expected = SafeMarkup::format($this->displayOptions['settings']['past_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']])
|
||||
$expected = new FormattableMarkup($this->displayOptions['settings']['past_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
|
||||
]);
|
||||
$output = $this->renderTestEntity($id);
|
||||
$this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
|
||||
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
|
||||
|
||||
// Verify that the 'datetime_time_ago' formatter works for intervals in the
|
||||
// future. First update the test entity so that the date difference always
|
||||
@@ -363,11 +361,11 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
|
||||
->setComponent($field_name, $this->displayOptions)
|
||||
->save();
|
||||
$expected = SafeMarkup::format($this->displayOptions['settings']['future_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']])
|
||||
$expected = new FormattableMarkup($this->displayOptions['settings']['future_format'], [
|
||||
'@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
|
||||
]);
|
||||
$output = $this->renderTestEntity($id);
|
||||
$this->assertContains((string) $expected, $output, SafeMarkup::format('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
|
||||
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -648,7 +646,7 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
$this->drupalCreateContentType(['type' => 'date_content']);
|
||||
|
||||
// Create a field storage with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
@@ -855,7 +853,7 @@ class DateTimeFieldTest extends DateTestBase {
|
||||
$this->drupalCreateContentType(['type' => 'date_content']);
|
||||
|
||||
// Create a field storage with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
|
||||
+1
-1
@@ -7,8 +7,8 @@ use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityTest\EntityTestResourceTestBase;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -7,8 +7,8 @@ use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityTest\EntityTestResourceTestBase;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ class ArgumentDateTimeTest extends DateTimeHandlerTestBase {
|
||||
'type' => 'page',
|
||||
'field_date' => [
|
||||
'value' => $date,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$node->save();
|
||||
$this->nodes[] = $node;
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace Drupal\Tests\datetime\Kernel\Views;
|
||||
|
||||
use Drupal\Component\Datetime\DateTimePlus;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
@@ -28,6 +30,13 @@ abstract class DateTimeHandlerTestBase extends ViewsKernelTestBase {
|
||||
*/
|
||||
protected static $field_name = 'field_date';
|
||||
|
||||
/**
|
||||
* Type of the field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $field_type = 'datetime';
|
||||
|
||||
/**
|
||||
* Nodes to test.
|
||||
*
|
||||
@@ -48,13 +57,13 @@ abstract class DateTimeHandlerTestBase extends ViewsKernelTestBase {
|
||||
// Add a date field to page nodes.
|
||||
$node_type = NodeType::create([
|
||||
'type' => 'page',
|
||||
'name' => 'page'
|
||||
'name' => 'page',
|
||||
]);
|
||||
$node_type->save();
|
||||
$fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => static::$field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'datetime',
|
||||
'type' => static::$field_type,
|
||||
'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
|
||||
]);
|
||||
$fieldStorage->save();
|
||||
@@ -91,4 +100,42 @@ abstract class DateTimeHandlerTestBase extends ViewsKernelTestBase {
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns UTC timestamp of user's TZ 'now'.
|
||||
*
|
||||
* The date field stores date_only values without conversion, considering them
|
||||
* already as UTC. This method returns the UTC equivalent of user's 'now' as a
|
||||
* unix timestamp, so they match using Y-m-d format.
|
||||
*
|
||||
* @return int
|
||||
* Unix timestamp.
|
||||
*/
|
||||
protected function getUTCEquivalentOfUserNowAsTimestamp() {
|
||||
$user_now = new DateTimePlus('now', new \DateTimeZone(drupal_get_user_timezone()));
|
||||
$utc_equivalent = new DateTimePlus($user_now->format('Y-m-d H:i:s'), new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE));
|
||||
|
||||
return $utc_equivalent->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array formatted date_only values relative to timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* Unix Timestamp used as 'today'.
|
||||
*
|
||||
* @return array
|
||||
* An array of DateTimeItemInterface::DATE_STORAGE_FORMAT date values. In
|
||||
* order tomorrow, today and yesterday.
|
||||
*/
|
||||
protected function getRelativeDateValuesFromTimestamp($timestamp) {
|
||||
return [
|
||||
// Tomorrow.
|
||||
\Drupal::service('date.formatter')->format($timestamp + 86400, 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE),
|
||||
// Today.
|
||||
\Drupal::service('date.formatter')->format($timestamp, 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE),
|
||||
// Yesterday.
|
||||
\Drupal::service('date.formatter')->format($timestamp - 86400, 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\datetime\Kernel\Views;
|
||||
|
||||
use Drupal\Component\Datetime\DateTimePlus;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\Node;
|
||||
@@ -182,44 +181,6 @@ class FilterDateTest extends DateTimeHandlerTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns UTC timestamp of user's TZ 'now'.
|
||||
*
|
||||
* The date field stores date_only values without conversion, considering them
|
||||
* already as UTC. This method returns the UTC equivalent of user's 'now' as a
|
||||
* unix timestamp, so they match using Y-m-d format.
|
||||
*
|
||||
* @return int
|
||||
* Unix timestamp.
|
||||
*/
|
||||
protected function getUTCEquivalentOfUserNowAsTimestamp() {
|
||||
$user_now = new DateTimePlus('now', new \DateTimeZone(drupal_get_user_timezone()));
|
||||
$utc_equivalent = new DateTimePlus($user_now->format('Y-m-d H:i:s'), new \DateTimeZone(DATETIME_STORAGE_TIMEZONE));
|
||||
|
||||
return $utc_equivalent->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array formatted date_only values.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* Unix Timestamp equivalent to user's "now".
|
||||
*
|
||||
* @return array
|
||||
* An array of DATETIME_DATE_STORAGE_FORMAT date values. In order tomorrow,
|
||||
* today and yesterday.
|
||||
*/
|
||||
protected function getRelativeDateValuesFromTimestamp($timestamp) {
|
||||
return [
|
||||
// Tomorrow.
|
||||
\Drupal::service('date.formatter')->format($timestamp + 86400, 'custom', DATETIME_DATE_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE),
|
||||
// Today.
|
||||
\Drupal::service('date.formatter')->format($timestamp, 'custom', DATETIME_DATE_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE),
|
||||
// Yesterday.
|
||||
\Drupal::service('date.formatter')->format($timestamp - 86400, 'custom', DATETIME_DATE_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates tests nodes date fields values.
|
||||
*
|
||||
|
||||
@@ -59,7 +59,7 @@ class FilterDateTimeTest extends DateTimeHandlerTestBase {
|
||||
'type' => 'page',
|
||||
'field_date' => [
|
||||
'value' => $date,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$node->save();
|
||||
$this->nodes[] = $node;
|
||||
|
||||
@@ -39,7 +39,7 @@ class SortDateTimeTest extends DateTimeHandlerTestBase {
|
||||
'type' => 'page',
|
||||
'field_date' => [
|
||||
'value' => $date,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$node->save();
|
||||
$this->nodes[] = $node;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\datetime\Unit\Plugin\migrate\field;
|
||||
|
||||
/**
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class DateFieldLegacyTest extends DateFieldTest {
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testUnknownDateType($method = 'processFieldValues') {
|
||||
parent::testUnknownDateType($method);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,25 +11,15 @@ use Drupal\Tests\UnitTestCase;
|
||||
*/
|
||||
class DateFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* Tests an Exception is thrown when the field type is not a known date type.
|
||||
*/
|
||||
public function testUnknownDateType() {
|
||||
$this->migration = $this->prophesize('Drupal\migrate\Plugin\MigrationInterface')->reveal();
|
||||
$this->plugin = new DateField([], '', []);
|
||||
public function testUnknownDateType($method = 'defineValueProcessPipeline') {
|
||||
$migration = $this->prophesize('Drupal\migrate\Plugin\MigrationInterface')->reveal();
|
||||
$plugin = new DateField([], '', []);
|
||||
|
||||
$this->setExpectedException(MigrateException::class, "Field field_date of type 'timestamp' is an unknown date field type.");
|
||||
$this->plugin->processFieldValues($this->migration, 'field_date', ['type' => 'timestamp']);
|
||||
$plugin->$method($migration, 'field_date', ['type' => 'timestamp']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\datetime\Unit\Plugin\migrate\field\d6;
|
||||
|
||||
/**
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class DateFieldLegacyTest extends DateFieldTest {
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testUnknownDateType($method = 'processFieldValues') {
|
||||
parent::testUnknownDateType($method);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Drupal\Tests\datetime\Unit\Plugin\migrate\field\d6;
|
||||
|
||||
use Drupal\datetime\Plugin\migrate\field\d6\DateField;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
@@ -12,25 +13,30 @@ use Drupal\Tests\UnitTestCase;
|
||||
*/
|
||||
class DateFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* Tests an Exception is thrown when the field type is not a known date type.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testUnknownDateType() {
|
||||
$this->migration = $this->prophesize('Drupal\migrate\Plugin\MigrationInterface')->reveal();
|
||||
$this->plugin = new DateField([], '', []);
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an Exception is thrown when the field type is not a known date type.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @expectedDeprecation 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.
|
||||
*/
|
||||
public function testUnknownDateType($method = 'defineValueProcessPipeline') {
|
||||
$plugin = new DateField([], '', []);
|
||||
|
||||
$this->setExpectedException(MigrateException::class, "Field field_date of type 'timestamp' is an unknown date field type.");
|
||||
$this->plugin->processFieldValues($this->migration, 'field_date', ['type' => 'timestamp']);
|
||||
$plugin->$method($this->migration, 'field_date', ['type' => 'timestamp']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user