Resolve #3187004 "Drupaldatetime serialization issue"
Closes #3187004
Merge request reports
Activity
added 1 commit
- 7f49b3a0 - Update core/lib/Drupal/Core/Datetime/DrupalDateTime.php
163 163 return $value; 164 164 } 165 165 166 /** 167 * Magic __sleep() method to avoid serializing formatTranslationCache. changed this line in version 5 of the diff
239 239 $this->assertEquals('America/New_York', $drupaldatetime->getTimezone()->getName()); 240 240 } 241 241 242 /** 243 * Test to avoid serialization of formatTranslationCache 244 */ 245 public function testSleep() { 163 163 return $value; 164 164 } 165 165 166 /** 167 * Magic __sleep() method to avoid serializing formatTranslationCache. 168 */ 169 public function __sleep() { 170 return ['langcode', 'dateTimeObject']; There is an implementation of
__sleep
method, but I don't see the one for__wakeup
. Please consider usingDependencySerializationTrait
to make sure serialization is done properly.Once we have
DependencySerializationTrait
in place, we can override__sleep
method and exclude problematic properties. If this property isformatTranslationCache
, then it might look like this:public function __sleep() { return array_diff(parent::__sleep(), ['formatTranslationCache']); {
Edited by Ivan Doroshenkochanged this line in version 5 of the diff
@Matroskeen, I've updated as per you suggestions. Can you please review this.
@mohit_rocks, it looks good, thanks!
I have just one question: is it necessary to add aliases for the trait methods or we could just use
parent::__sleep()
orparent::__wakeup()
? I noticed we have both patterns in core so I'm just wondering if this is a personal preference or there is some use-case when one variation works better than other.