Skip to content
Snippets Groups Projects
Commit 9a6ef7f2 authored by jrockowitz's avatar jrockowitz
Browse files

Merge branch '8.x-5.x' into 6.x

parents 60f15703 a3385d1c
No related branches found
Tags 7.x-1.0
No related merge requests found
......@@ -7,6 +7,8 @@ use Drupal\Core\Serialization\Yaml;
use Drupal\webform\EntityStorage\WebformEntityStorageTrait;
use Drupal\webform\Utility\WebformArrayHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Component\Datetime\TimeInterface;
/**
* Provides a WebformSubmissionDevelGenerate plugin.
......@@ -64,6 +66,13 @@ trait WebformSubmissionDevelGenerateTrait {
*/
protected $messenger;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* {@inheritdoc}
*/
......@@ -75,6 +84,7 @@ trait WebformSubmissionDevelGenerateTrait {
$instance->messenger = $container->get('messenger');
$instance->webformSubmissionGenerate = $container->get('webform_submission.generate');
$instance->webformEntityReferenceManager = $container->get('webform.entity_reference_manager');
$instance->time = $container->get('datetime.time');
return $instance;
}
......@@ -224,11 +234,11 @@ trait WebformSubmissionDevelGenerateTrait {
}
if (!empty($values['webform_ids'])) {
$this->initializeGenerate($values);
$start = time();
$start = $this->time->getRequestTime();
for ($i = 1; $i <= $values['num']; $i++) {
$this->generateSubmission($values);
if (function_exists('drush_log') && $i % drush_get_option('feedback', 1000) === 0) {
$now = time();
$now = $this->time->getRequestTime();
$dt_args = [
'@feedback' => drush_get_option('feedback', 1000),
'@rate' => (drush_get_option('feedback', 1000) * 60) / ($now - $start),
......@@ -274,7 +284,7 @@ trait WebformSubmissionDevelGenerateTrait {
// Set created min and max.
$values['created_min'] = strtotime('-1 month');
$values['created_max'] = time();
$values['created_max'] = $this->time->getRequestTime();
// Set entity type and id default value.
$values += [
......
......@@ -28,6 +28,13 @@ abstract class WebformEntityReferenceFormatterBase extends EntityReferenceFormat
*/
protected $configFactory;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* {@inheritdoc}
*/
......@@ -43,6 +50,7 @@ abstract class WebformEntityReferenceFormatterBase extends EntityReferenceFormat
);
$instance->configFactory = $container->get('config.factory');
$instance->renderer = $container->get('renderer');
$instance->time = $container->get('datetime.time');
return $instance;
}
......@@ -102,8 +110,8 @@ abstract class WebformEntityReferenceFormatterBase extends EntityReferenceFormat
foreach ($states as $state) {
if ($item->status === WebformInterface::STATUS_SCHEDULED) {
$item_state = $item->$state;
if ($item_state && strtotime($item_state) > time()) {
$item_seconds = strtotime($item_state) - time();
if ($item_state && strtotime($item_state) > $this->time->getRequestTime()) {
$item_seconds = strtotime($item_state) - $this->time->getRequestTime();
if (!$max_age && $item_seconds > $max_age) {
$max_age = $item_seconds;
}
......@@ -111,8 +119,8 @@ abstract class WebformEntityReferenceFormatterBase extends EntityReferenceFormat
}
if ($webform->status() === WebformInterface::STATUS_SCHEDULED) {
$webform_state = $webform->get($state);
if ($webform_state && strtotime($webform_state) > time()) {
$webform_seconds = strtotime($webform_state) - time();
if ($webform_state && strtotime($webform_state) > $this->time->getRequestTime()) {
$webform_seconds = strtotime($webform_state) - $this->time->getRequestTime();
if (!$max_age && $webform_seconds > $max_age) {
$max_age = $webform_seconds;
}
......
......@@ -685,7 +685,7 @@ abstract class DateBase extends WebformElementBase {
protected static function formatDate($custom_format, $timestamp = NULL) {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
return $date_formatter->format($timestamp ?: time(), 'custom', $custom_format);
return $date_formatter->format($timestamp ?: \Drupal::time()->getRequestTime(), 'custom', $custom_format);
}
/**
......
......@@ -156,7 +156,7 @@ class WebformTime extends WebformElementBase {
protected static function formatTime($custom_format, $timestamp = NULL) {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
return $date_formatter->format($timestamp ?: time(), 'custom', $custom_format);
return $date_formatter->format($timestamp ?: \Drupal::time()->getRequestTime(), 'custom', $custom_format);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment