Unverified Commit d23b4cc8 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3112295 by mpdonadio, Hardik_Patel_12, daffie, JeroenT, Vlad Bo,...

Issue #3112295 by mpdonadio, Hardik_Patel_12, daffie, JeroenT, Vlad Bo, pifagor, voleger, alexpott: Replace REQUEST_TIME in OO code w/o access to the container
parent 42b761c3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -291,10 +291,10 @@ public static function weekDaysOrdered($weekdays) {
  public static function years($min = 0, $max = 0, $required = FALSE) {
    // Ensure $min and $max are valid values.
    if (empty($min)) {
      $min = intval(date('Y', REQUEST_TIME) - 3);
      $min = intval(date('Y', \Drupal::time()->getRequestTime()) - 3);
    }
    if (empty($max)) {
      $max = intval(date('Y', REQUEST_TIME) + 3);
      $max = intval(date('Y', \Drupal::time()->getRequestTime()) + 3);
    }
    $none = ['' => ''];
    $range = range($min, $max);
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public function settingsForm(array $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(\Drupal::time()->getRequestTime(), $machine_name)]);
    }

    $date_formats['custom'] = $this->t('Custom');
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ public function preSave() {

    // Set the timestamp to request time if it is not set.
    if (!$this->value) {
      $this->value = REQUEST_TIME;
      $this->value = \Drupal::time()->getRequestTime();
    }
    else {
      // On an existing entity translation, the changed timestamp will only be
@@ -47,7 +47,7 @@ public function preSave() {
      if (!$entity->isNew() && $original && $original->hasTranslation($langcode)) {
        $original_value = $original->getTranslation($langcode)->get($this->getFieldDefinition()->getName())->value;
        if ($this->value == $original_value && $entity->hasTranslationChanges()) {
          $this->value = REQUEST_TIME;
          $this->value = \Drupal::time()->getRequestTime();
        }
      }
    }
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ class CreatedItem extends TimestampItem {
  public function applyDefaultValue($notify = TRUE) {
    parent::applyDefaultValue($notify);
    // Created fields default to the current timestamp.
    $this->setValue(['value' => REQUEST_TIME], $notify);
    $this->setValue(['value' => \Drupal::time()->getRequestTime()], $notify);
    return $this;
  }

+4 −4
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public function has($key) {
    return (bool) $this->connection->query('SELECT 1 FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name = :key AND expire > :now', [
      ':collection' => $this->collection,
      ':key' => $key,
      ':now' => REQUEST_TIME,
      ':now' => \Drupal::time()->getRequestTime(),
    ])->fetchField();
  }

@@ -47,7 +47,7 @@ public function getMultiple(array $keys) {
    $values = $this->connection->query(
      'SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE expire > :now AND name IN ( :keys[] ) AND collection = :collection',
      [
        ':now' => REQUEST_TIME,
        ':now' => \Drupal::time()->getRequestTime(),
        ':keys[]' => $keys,
        ':collection' => $this->collection,
      ])->fetchAllKeyed();
@@ -62,7 +62,7 @@ public function getAll() {
      'SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND expire > :now',
      [
        ':collection' => $this->collection,
        ':now' => REQUEST_TIME,
        ':now' => \Drupal::time()->getRequestTime(),
      ])->fetchAllKeyed();
    return array_map([$this->serializer, 'decode'], $values);
  }
@@ -78,7 +78,7 @@ public function setWithExpire($key, $value, $expire) {
      ])
      ->fields([
        'value' => $this->serializer->encode($value),
        'expire' => REQUEST_TIME + $expire,
        'expire' => \Drupal::time()->getRequestTime() + $expire,
      ])
      ->execute();
  }
Loading