Skip to content
Snippets Groups Projects
Commit 86aacdff authored by catch's avatar catch
Browse files

Issue #3395986 by Taran2L, quietone, Spokje, andypost, smustgrave: Replace...

Issue #3395986 by Taran2L, quietone, Spokje, andypost, smustgrave: Replace REQUEST_TIME in plugins with direct container access
parent 2d17900f
No related branches found
No related tags found
24 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #96925 passed with warnings
......@@ -2,6 +2,7 @@
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Datetime\DateFormatterInterface;
......@@ -49,6 +50,13 @@ class TimestampFormatter extends FormatterBase {
*/
protected $dateFormatStorage;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs a new TimestampFormatter.
*
......@@ -70,12 +78,30 @@ class TimestampFormatter extends FormatterBase {
* The date formatter service.
* @param \Drupal\Core\Entity\EntityStorageInterface $date_format_storage
* The date format storage.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateFormatterInterface $date_formatter, EntityStorageInterface $date_format_storage) {
public function __construct(
$plugin_id,
$plugin_definition,
FieldDefinitionInterface $field_definition,
array $settings,
$label,
$view_mode,
array $third_party_settings,
DateFormatterInterface $date_formatter,
EntityStorageInterface $date_format_storage,
?TimeInterface $time = NULL,
) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->dateFormatter = $date_formatter;
$this->dateFormatStorage = $date_format_storage;
if (!$time) {
@trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3395991', E_USER_DEPRECATED);
$time = \Drupal::service('datetime.time');
}
$this->time = $time;
}
/**
......@@ -91,7 +117,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration['view_mode'],
$configuration['third_party_settings'],
$container->get('date.formatter'),
$container->get('entity_type.manager')->getStorage('date_format')
$container->get('entity_type.manager')->getStorage('date_format'),
$container->get('datetime.time'),
);
}
......@@ -124,8 +151,9 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$date_formats = [];
$requestTime = $this->time->getRequestTime();
foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) {
$date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)]);
$date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format($requestTime, $machine_name)]);
}
$date_formats[static::CUSTOM_DATE_FORMAT] = $this->t('Custom');
......
......@@ -2,6 +2,7 @@
namespace Drupal\datetime\Plugin\views\argument;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
......@@ -38,8 +39,19 @@ class Date extends NumericDate {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, DateFormatterInterface $date_formatter) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match, $date_formatter);
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
RouteMatchInterface $route_match,
DateFormatterInterface $date_formatter,
?TimeInterface $time = NULL,
) {
if (!$time) {
@trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3395991', E_USER_DEPRECATED);
$time = \Drupal::service('datetime.time');
}
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match, $date_formatter, $time);
$definition = $this->getFieldStorageDefinition();
if ($definition->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
......
......@@ -2,9 +2,11 @@
namespace Drupal\history\Plugin\views\filter;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\UncacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Filter for new content.
......@@ -25,6 +27,38 @@ class HistoryUserTimestamp extends FilterPluginBase {
*/
public $no_operator = TRUE;
/**
* Constructs a HistoryUserTimestamp object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Component\Datetime\TimeInterface|null $time
* The time service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, protected ?TimeInterface $time = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if (!$time) {
@trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3395991', E_USER_DEPRECATED);
$this->time = \Drupal::service('datetime.time');
}
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('datetime.time'),
);
}
/**
* {@inheritdoc}
*/
......@@ -81,7 +115,7 @@ public function query() {
// Hey, Drupal kills old history, so nodes that haven't been updated
// since HISTORY_READ_LIMIT are outta here!
$limit = REQUEST_TIME - HISTORY_READ_LIMIT;
$limit = $this->time->getRequestTime() - HISTORY_READ_LIMIT;
$this->ensureMyTable();
$field = "$this->tableAlias.$this->realField";
......
......@@ -140,7 +140,7 @@ public function createFetchTask($project) {
if (empty($this->fetchTasks[$project['name']])) {
$this->fetchQueue->createItem($project);
$this->fetchTaskStore->set($project['name'], $project);
$this->fetchTasks[$project['name']] = REQUEST_TIME;
$this->fetchTasks[$project['name']] = $this->time->getRequestTime();
}
}
......@@ -166,9 +166,8 @@ public function fetchData() {
public function processFetchTask($project) {
global $base_url;
// This can be in the middle of a long-running batch, so REQUEST_TIME won't
// necessarily be valid.
$request_time_difference = time() - REQUEST_TIME;
// This can be in the middle of a long-running batch.
$request_time_difference = $this->time->getCurrentTime() - $this->time->getRequestTime();
if (empty($this->failed)) {
// If we have valid data about release history XML servers that we have
// failed to fetch from on previous attempts, load that.
......@@ -206,14 +205,14 @@ public function processFetchTask($project) {
}
$frequency = $this->updateSettings->get('check.interval_days');
$available['last_fetch'] = REQUEST_TIME + $request_time_difference;
$available['last_fetch'] = $this->time->getRequestTime() + $request_time_difference;
$this->availableReleasesTempStore->setWithExpire($project_name, $available, $request_time_difference + (60 * 60 * 24 * $frequency));
// Stash the $this->failed data back in the DB for the next 5 minutes.
$this->tempStore->setWithExpire('fetch_failures', $this->failed, $request_time_difference + (60 * 5));
// Whether this worked or not, we did just (try to) check for updates.
$this->stateStore->set('update.last_check', REQUEST_TIME + $request_time_difference);
$this->stateStore->set('update.last_check', $this->time->getRequestTime() + $request_time_difference);
// Now that we processed the fetch task for this project, clear out the
// record for this task so we're willing to fetch again.
......
......@@ -2,6 +2,7 @@
namespace Drupal\views\Plugin\views\argument;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -70,12 +71,25 @@ class Date extends Formula implements ContainerFactoryPluginInterface {
* The route match.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Component\Datetime\TimeInterface|null $time
* The time service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, DateFormatterInterface $date_formatter) {
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
RouteMatchInterface $route_match,
DateFormatterInterface $date_formatter,
protected ?TimeInterface $time = NULL,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $route_match;
$this->dateFormatter = $date_formatter;
if (!$time) {
@trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3395991', E_USER_DEPRECATED);
$this->time = \Drupal::service('datetime.time');
}
}
/**
......@@ -87,7 +101,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('current_route_match'),
$container->get('date.formatter')
$container->get('date.formatter'),
$container->get('datetime.time'),
);
}
......@@ -106,7 +121,7 @@ public function defaultArgumentForm(&$form, FormStateInterface $form_state) {
*/
public function getDefaultArgument($raw = FALSE) {
if (!$raw && $this->options['default_argument_type'] == 'date') {
return date($this->argFormat, REQUEST_TIME);
return date($this->argFormat, $this->time->getRequestTime());
}
elseif (!$raw && in_array($this->options['default_argument_type'], ['node_created', 'node_changed'])) {
$node = $this->routeMatch->getParameter('node');
......
......@@ -2,10 +2,11 @@
namespace Drupal\views\Plugin\views\cache;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Cache\Cache;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Simple caching of query results for Views displays.
......@@ -43,11 +44,16 @@ class Time extends CachePluginBase {
* The plugin implementation definition.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Component\Datetime\TimeInterface|null $time
* The time service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter) {
$this->dateFormatter = $date_formatter;
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter, protected ?TimeInterface $time = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->dateFormatter = $date_formatter;
if (!$time) {
@trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3395991', E_USER_DEPRECATED);
$this->time = \Drupal::service('datetime.time');
}
}
/**
......@@ -58,7 +64,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('date.formatter')
$container->get('date.formatter'),
$container->get('datetime.time'),
);
}
......@@ -144,7 +151,7 @@ protected function getLifespan($type) {
protected function cacheExpire($type) {
$lifespan = $this->getLifespan($type);
if ($lifespan) {
$cutoff = REQUEST_TIME - $lifespan;
$cutoff = $this->time->getRequestTime() - $lifespan;
return $cutoff;
}
else {
......
......@@ -3,6 +3,7 @@
namespace Drupal\views\Plugin\views\field;
use Drupal\Core\Datetime\TimeZoneFormHelper;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ResultRow;
......@@ -45,12 +46,25 @@ class Date extends FieldPluginBase {
* The date formatter service.
* @param \Drupal\Core\Entity\EntityStorageInterface $date_format_storage
* The date format storage.
* @param \Drupal\Component\Datetime\TimeInterface|null $time
* The time service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter, EntityStorageInterface $date_format_storage) {
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
DateFormatterInterface $date_formatter,
EntityStorageInterface $date_format_storage,
protected ?TimeInterface $time = NULL,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->dateFormatter = $date_formatter;
$this->dateFormatStorage = $date_format_storage;
if (!$time) {
@trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3395991', E_USER_DEPRECATED);
$this->time = \Drupal::service('datetime.time');
}
}
/**
......@@ -62,7 +76,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('date.formatter'),
$container->get('entity_type.manager')->getStorage('date_format')
$container->get('entity_type.manager')->getStorage('date_format'),
$container->get('datetime.time'),
);
}
......@@ -86,7 +101,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$date_formats = [];
foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) {
$date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)]);
$date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format($this->time->getRequestTime(), $machine_name)]);
}
$form['date_format'] = [
......@@ -146,7 +161,7 @@ public function render(ResultRow $values) {
$timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
// Will be positive for a datetime in the past (ago), and negative for a
// datetime in the future (hence).
$time_diff = REQUEST_TIME - $value;
$time_diff = $this->time->getRequestTime() - $value;
switch ($format) {
case 'raw time ago':
return $this->dateFormatter->formatTimeDiffSince($value, ['granularity' => is_numeric($custom_format) ? $custom_format : 2]);
......
......@@ -637,11 +637,6 @@ parameters:
count: 1
path: lib/Drupal/Core/Field/FieldTypePluginManager.php
-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
count: 1
path: lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php
-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
count: 2
......@@ -1343,11 +1338,6 @@ parameters:
count: 1
path: modules/history/src/Plugin/views/field/HistoryUserTimestamp.php
-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
count: 1
path: modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
-
message: "#^Variable \\$image_style in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
......@@ -2071,14 +2061,6 @@ parameters:
count: 1
path: modules/system/tests/modules/lazy_route_provider_install_test/src/PluginManager.php
-
message: """
#^Class Drupal\\\\service_provider_test\\\\TestClass implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
since Symfony 6\\.4, use dependency injection instead$#
"""
count: 1
path: modules/system/tests/modules/service_provider_test/src/TestClass.php
-
message: "#^Missing cache backend declaration for performance\\.$#"
count: 1
......@@ -2104,6 +2086,14 @@ parameters:
count: 1
path: modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php
-
message: """
#^Class Drupal\\\\service_provider_test\\\\TestClass implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
since Symfony 6\\.4, use dependency injection instead$#
"""
count: 1
path: modules/system/tests/modules/service_provider_test/src/TestClass.php
-
message: """
#^Usage of deprecated trait Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareTrait in class Drupal\\\\service_provider_test\\\\TestClass\\:
......@@ -2187,11 +2177,6 @@ parameters:
count: 1
path: modules/update/src/ProjectRelease.php
-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
count: 4
path: modules/update/src/UpdateProcessor.php
-
message: "#^Variable \\$users might not be defined\\.$#"
count: 1
......@@ -2358,21 +2343,11 @@ parameters:
count: 1
path: modules/views/src/Plugin/views/argument/Broken.php
-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
count: 1
path: modules/views/src/Plugin/views/argument/Date.php
-
message: "#^Method Drupal\\\\views\\\\Plugin\\\\views\\\\cache\\\\CachePluginBase\\:\\:cacheGet\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: modules/views/src/Plugin/views/cache/CachePluginBase.php
-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
count: 1
path: modules/views/src/Plugin/views/cache/Time.php
-
message: "#^Constructor of class Drupal\\\\views\\\\Plugin\\\\views\\\\display\\\\DisplayPluginBase has an unused parameter \\$configuration\\.$#"
count: 1
......@@ -2408,11 +2383,6 @@ parameters:
count: 1
path: modules/views/src/Plugin/views/field/BulkForm.php
-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
count: 2
path: modules/views/src/Plugin/views/field/Date.php
-
message: "#^Method Drupal\\\\views\\\\Plugin\\\\views\\\\field\\\\Date\\:\\:render\\(\\) should return Drupal\\\\Component\\\\Render\\\\MarkupInterface\\|string but return statement is missing\\.$#"
count: 1
......
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