Skip to content
Snippets Groups Projects
Verified Commit 6567f4f0 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3187004 by recrit, a.dmitriiev, mohit_aghera, ranjith_kumar_k_u,...

Issue #3187004 by recrit, a.dmitriiev, mohit_aghera, ranjith_kumar_k_u, larowlan, Matroskeen, smustgrave, Kristen Pol, neclimdul: DrupalDateTime serialization issue

(cherry picked from commit 6db12006)
parent 311c787f
No related branches found
No related tags found
9 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...
Pipeline #99190 passed
Pipeline: drupal

#99195

    ......@@ -3,6 +3,7 @@
    namespace Drupal\Core\Datetime;
    use Drupal\Component\Datetime\DateTimePlus;
    use Drupal\Core\DependencyInjection\DependencySerializationTrait;
    use Drupal\Core\StringTranslation\StringTranslationTrait;
    /**
    ......@@ -21,6 +22,9 @@
    class DrupalDateTime extends DateTimePlus {
    use StringTranslationTrait;
    use DependencySerializationTrait {
    __sleep as defaultSleep;
    }
    /**
    * Formatted strings translation cache.
    ......@@ -52,7 +56,7 @@ class DrupalDateTime extends DateTimePlus {
    *
    * @var array
    */
    protected $formatTranslationCache;
    protected $formatTranslationCache = [];
    /**
    * Constructs a date object.
    ......@@ -166,4 +170,11 @@ public function format($format, $settings = []) {
    return $value;
    }
    /**
    * {@inheritdoc}
    */
    public function __sleep(): array {
    return array_diff($this->defaultSleep(), ['formatTranslationCache']);
    }
    }
    ......@@ -271,4 +271,23 @@ public function testRfc2822DateFormat() {
    }
    }
    /**
    * Test to avoid serialization of formatTranslationCache.
    */
    public function testSleep(): void {
    $tz = new \DateTimeZone(date_default_timezone_get());
    $date = new DrupalDateTime('now', $tz, ['langcode' => 'en']);
    // Override timestamp before serialize.
    $date->setTimestamp(12345678);
    $vars = $date->__sleep();
    $this->assertContains('langcode', $vars);
    $this->assertContains('dateTimeObject', $vars);
    $this->assertNotContains('formatTranslationCache', $vars);
    $unserialized_date = unserialize(serialize($date));
    $this->assertSame(12345678, $unserialized_date->getTimestamp());
    }
    }
    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