summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-08-10 21:48:55 (GMT)
committerAlex Pott2018-08-10 21:49:02 (GMT)
commita58773c0215a127d472054bec3949a84bc25847a (patch)
tree853c932c4878d65b61f9821950ac90fd093ec55b
parent596caa3e51751a091587ed7784944fa183179494 (diff)
Issue #2893029 by phenaproxima, Sam152, tim.plunkett, alexpott, a.dmitriiev, dawehner, Berdir: EntityType objects cannot be reliably serialized without DependencySerializationTrait
(cherry picked from commit 02330aaa2083b89420292bada5b0421254a82c05)
-rw-r--r--core/lib/Drupal/Core/Entity/EntityType.php2
-rw-r--r--core/modules/system/tests/fixtures/update/drupal-8.language-enabled.phpbin6346 -> 6346 bytes
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php19
3 files changed, 21 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php
index e28fdb0..c6f320f 100644
--- a/core/lib/Drupal/Core/Entity/EntityType.php
+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -3,6 +3,7 @@
namespace Drupal\Core\Entity;
use Drupal\Component\Plugin\Definition\PluginDefinition;
+use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Entity\Exception\EntityTypeIdLengthException;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
@@ -14,6 +15,7 @@ use Drupal\Core\StringTranslation\TranslatableMarkup;
*/
class EntityType extends PluginDefinition implements EntityTypeInterface {
+ use DependencySerializationTrait;
use StringTranslationTrait;
/**
diff --git a/core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php b/core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php
index 05bcf8e..477d95e 100644
--- a/core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php
+++ b/core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php
Binary files differ
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
index b28a72c..4027647 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
@@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Entity;
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
+use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Tests\UnitTestCase;
/**
@@ -476,4 +477,22 @@ class EntityTypeTest extends UnitTestCase {
$this->assertEmpty($reflection->getProperties(\ReflectionProperty::IS_PUBLIC));
}
+ /**
+ * Tests that the EntityType object can be serialized.
+ */
+ public function testIsSerializable() {
+ $entity_type = $this->setUpEntityType([]);
+
+ $translation = $this->prophesize(TranslationInterface::class);
+ $translation->willImplement(\Serializable::class);
+ $translation->serialize()->willThrow(\Exception::class);
+ $translation_service = $translation->reveal();
+ $translation_service->_serviceId = 'string_translation';
+
+ $entity_type->setStringTranslation($translation_service);
+ $entity_type = unserialize(serialize($entity_type));
+
+ $this->assertEquals('example_entity_type', $entity_type->id());
+ }
+
}