Commit 28c003ba authored by catch's avatar catch
Browse files

Issue #2615790 by Xano: Field item properties do not prevent the services they...

Issue #2615790 by Xano: Field item properties do not prevent the services they contain from being serialized
parent 5016b9c6
......@@ -199,4 +199,23 @@ public function getPropertyPath() {
public function getParent() {
return $this->parent;
}
/**
* {@inheritdoc}
*/
public function __sleep() {
$vars = get_object_vars($this);
// Prevent services from being serialized. static::getStringTranslation()
// and static::getTypedDataManager() lazy-load them after $this has been
// unserialized.
// @todo Replace this with
// \Drupal\Core\DependencyInjection\DependencySerializationTrait before
// Drupal 9.0.0. We cannot use that now, because child classes already use
// it and PHP 5 would consider that conflicts.
unset($vars['stringTranslation']);
unset($vars['typedDataManager']);
return array_keys($vars);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\Core\TypedData\TypedDataTest.
*/
namespace Drupal\Tests\Core\TypedData;
use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\TypedData\TypedData;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\TypedData\TypedData
*
* @group TypedData
*/
class TypedDataTest extends UnitTestCase {
/**
* @covers ::__sleep
*/
public function testSleep() {
$data_definition = $this->getMock(DataDefinitionInterface::class);
/** @var \Drupal\Core\TypedData\TypedData $typed_data */
$typed_data = $this->getMockForAbstractClass(TypedData::class, [$data_definition]);
$string_translation = $this->getStringTranslationStub();
$typed_data->setStringTranslation($string_translation);
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$typed_data->setTypedDataManager($typed_data_manager);
$serialized_typed_data = serialize($typed_data);
$this->assertNotContains(get_class($string_translation), $serialized_typed_data);
$this->assertNotContains(get_class($typed_data_manager), $serialized_typed_data);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment