Skip to content

Commit

Permalink
refactor: removed deprecated REQUEST_TIME
Browse files Browse the repository at this point in the history
  • Loading branch information
w-lopes committed Jan 21, 2022
1 parent 577334a commit 72975a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/Plugin/Field/FieldType/PublicationDateItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class PublicationDateItem extends ChangedItem {
* {@inheritdoc}
*/
public function applyDefaultValue($notify = TRUE) {
$value = $this->isPublished() ? REQUEST_TIME : NULL;
$published_at_or_now = isset($value) ? $value : REQUEST_TIME;
$request_time = \Drupal::time()->getRequestTime();
$value = $this->isPublished() ? $request_time : NULL;
$published_at_or_now = isset($value) ? $value : $request_time;
$this->setValue(['value' => $value, 'published_at_or_now' => $published_at_or_now], $notify);
return $this;
}
Expand All @@ -59,6 +60,7 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
* {@inheritdoc}
*/
public function preSave() {
$request_time = \Drupal::time()->getRequestTime();
// If no publication date has been set and the entity is unpublished then
// store the default publication date.
if (!$this->isPublished() && !$this->value) {
Expand All @@ -67,12 +69,12 @@ public function preSave() {
// If the default publication date is set and the entity is published then
// store the current date.
elseif ($this->isPublished() && $this->value == PUBLICATION_DATE_DEFAULT) {
$this->value = REQUEST_TIME;
$this->value = $request_time;
}

// Set the timestamp to request time if it is not set.
if (!$this->value) {
$this->value = REQUEST_TIME;
$this->value = $request_time;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tests/PublicationDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
namespace Drupal\publication_date\Tests;

use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\UnitTestCase;

/**
* Tests for publication_date.
*
* @group publication_date
*/
class PublicationDateTest extends WebTestBase {
class PublicationDateTest extends UnitTestCase {

/**
* Modules to enable.
Expand Down

0 comments on commit 72975a0

Please sign in to comment.