Entities tend to get serialized in various places : cache, forms...

ConfigEntities, being more business oriented, additionally tend to get more business specific helper methods, possibly relying on internal properties / derived data / external services, other than their raw data, and which you usually don't want to serialize.

Nice thing is, ConfigEntities have a pretty straightforward serialization format: the exported properties that end up in their CMI file...

We had to do this for Field / FieldInstance entities, that fall exactly in this case above, but the code is pretty agnostic and might make sense for all ConfigEntity types.
(since then, #2205367: [HEAD BROKEN] PHP 5.4 duplicated that same code in EntityFormDisplay - leaving the symmetrical EntityViewDisplay out).

Basically, serialize to the raw array returned by getExportProperties() (as if it was going to CMI), and unserialize by passing this array to __construct() (just as if it was read from config). Same format, different storage.

Patch once I get a node id.

Files: 
CommentFileSizeAuthor
#17 interdiff.txt1.6 KBswentel
#17 ConfigEntity-serialize-1977206-17.patch5.55 KBswentel
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,051 pass(es), 14 fail(s), and 6 exception(s).
[ View ]
#14 interdiff.txt578 bytesyched
#14 ConfigEntity-serialize-1977206-14.patch4.7 KByched
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 64,473 pass(es), 23 fail(s), and 12 exception(s).
[ View ]
#11 interdiff.txt1.05 KByched
#11 ConfigEntity-serialize-1977206-11.patch4.66 KByched
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 64,052 pass(es), 34 fail(s), and 10,559 exception(s).
[ View ]
#10 interdiff.txt1.15 KByched
#10 ConfigEntity-serialize-1977206-10.patch5.67 KByched
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 64,076 pass(es), 34 fail(s), and 10,538 exception(s).
[ View ]
#6 ConfigEntity-serialize-1977206-6.patch4.38 KByched
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Failed to run tests: PHP Fatal error encountered during run_tests.sh. See review log for details..
[ View ]
#1 ConfigEntity-serialize-1977206-1.patch3.16 KByched
FAILED: [[SimpleTest]]: [MySQL] 54,912 pass(es), 8 fail(s), and 4 exception(s).
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new3.16 KB
FAILED: [[SimpleTest]]: [MySQL] 54,912 pass(es), 8 fail(s), and 4 exception(s).
[ View ]

Patch.

Status:Needs review» Needs work

The last submitted patch, ConfigEntity-serialize-1977206-1.patch, failed testing.

There's related issue #1818574: Convert config entities to the new Entity Field API and I hit the bug in #1907960-148: Helper issue for "Comment field" where unserialized value turns into string

So, yeah, Views config entities seem to have an issue with this, because there's a 2-way crossreference with the associated ViewExecutable. Got lost trying to unfold this, would welcome feedback from the Views team.

#1875992: Add EntityFormDisplay objects for entity forms is another example of a config entity that would need to duplicate the exact same serialize / unserialize logic added here.

Issue summary:View changes

Phrasing

Issue summary:View changes
Issue tags:-Field API+Entity Field API
StatusFileSize
new4.38 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Failed to run tests: PHP Fatal error encountered during run_tests.sh. See review log for details..
[ View ]

Reviving this after #2205367: [HEAD BROKEN] PHP 5.4.

Content entities have default serialization code in ContentEntityBase now, config entities should have theirs too.

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 6: ConfigEntity-serialize-1977206-6.patch, failed testing.

I had a quick look at why this is failing (fatal errors is usually phpunit fails) and the reason is that mocking a class without invoking the constructor goes through unserialize(), which in turn calls __wakeup(), which then calls the constructor anyway o.0

See PHPUnit_Framework_MockObject_Generator::getObjects().

The test that is failing is TourTest.

Status:Needs work» Needs review
StatusFileSize
new5.67 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 64,076 pass(es), 34 fail(s), and 10,538 exception(s).
[ View ]
new1.15 KB

Ouch - right, nice find :

<?php
PHPUnit_Framework_MockObject_Generator
::getObject() :
if (
$callOriginalConstructor) {
  ...
} else {
 
// Use a trick to create a new object of a class
  // without invoking its constructor.
 
$object = unserialize('O:%d:"%s":0:{}', strlen($className), $className);
}
?>

Nasty.

Fixed TourTest to call the Tour config entity constructor, which requires placing a mocked plugin.manager.tour.tip in the container :-/
Other unit tests are green at home.

StatusFileSize
new4.66 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 64,052 pass(es), 34 fail(s), and 10,559 exception(s).
[ View ]
new1.05 KB

Altough another approach could be to add a safeguard to our __wakeup()

Alternate to #10, interdiff is against #6.

The last submitted patch, 10: ConfigEntity-serialize-1977206-10.patch, failed testing.

Status:Needs review» Needs work

The last submitted patch, 11: ConfigEntity-serialize-1977206-11.patch, failed testing.

Status:Needs work» Needs review
StatusFileSize
new4.7 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 64,473 pass(es), 23 fail(s), and 12 exception(s).
[ View ]
new578 bytes

Right, FieldConfig::__sleep() had an additional safeguard: the keys returned by getExportProperties() do not necessarily correspond to actual object properties.

Status:Needs review» Needs work

The last submitted patch, 14: ConfigEntity-serialize-1977206-14.patch, failed testing.

+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -268,4 +268,32 @@ public function url($rel = 'edit-form', $options = array()) {
+    // PHPUnit uses unserilalize() on a made up string as a trick when bypassing

unserilalize - sounds very musical :)

StatusFileSize
new5.55 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,051 pass(es), 14 fail(s), and 6 exception(s).
[ View ]
new1.6 KB

Had a quick peek in the editor admin test and remembered this issue: #2207777: Can not configure editor whilst creating a new text format
So changing the test a little fixes the issue, but that's probably not the right way since it didn't fail before .. posting the patch though as it may trigger ideas.

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 17: ConfigEntity-serialize-1977206-17.patch, failed testing.

The last submitted patch, 17: ConfigEntity-serialize-1977206-17.patch, failed testing.