Is there a reason why json was chosen above yaml?
If not, I might look into it making a patch.

Comments

betz created an issue. See original summary.

samuel.mortenson’s picture

@betz There wasn't really - I just wasn't sure if core's normalization supported YAML as a format. If it does I'd be happy to review a patch.

samuel.mortenson’s picture

Status: Active » Closed (won't fix)

I just looked into this, it looks like there is no Symphony serializer support for YML, so I don't think I'm going to support it in Tome. Core's test coverage for entity serialization also uses JSON (and XML, and HAL-JSON), so I don't want to go into uncharted territory with using YML.

The good news is that contrib, or a sub-module of Tome, could override the tome.storage.content service (using service decorators, I think?) to use any format they want (including remote storage!), so there are options going forward.

I'm going to close this issue, but if you can come up with a patch that adds a sub-module that uses YML I'll look into adding it. For now I'm sticking with JSON going forward. Thanks!

samuel.mortenson’s picture

Assigned: Unassigned » samuel.mortenson
Status: Closed (won't fix) » Active

This is possible now

samuel.mortenson’s picture

Title: YAML » Add YAML as an optional entity storage format
Component: Code » Tome Sync
samuel.mortenson’s picture

Status: Active » Needs review
StatusFileSize
new9.79 KB

Here's a start to this, which appears to work. Core doesn't have an encoder for Yaml yet which is what I thought originally, but it turns out making out own makes sense for controlling the output.

samuel.mortenson’s picture

StatusFileSize
new11.77 KB
new1.86 KB

Added importer tests as well.

larowlan’s picture

+++ b/modules/tome_sync/tests/src/Kernel/ExporterTest.php
@@ -208,4 +208,48 @@ class ExporterTest extends TestBase {
+    $this->assertFileExists($yml_file);

should you assert something about the contents of the file too?

Looks good, but from memory we didn't use YAML as an export format in core for security reasons.

samuel.mortenson’s picture

@larowlan YAML is scarier but AFAIK Symfony's encoder with the flags I'm using should be fine, no object or constant parsing, but I'll double check that.

For the test coverage - this is mimicking the JSON test coverage in the same file, basically the fact that the file storage works and the entity is denormalized is good enough for me. However I am doing some tricky (and likely stupid) things with the YAML so I could check that mullti-line strings work.

samuel.mortenson’s picture

Also just saw that https://www.drupal.org/project/default_content uses Yaml as of 2.0 - our modules have a lot of overlap lol!

bserem’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch and things were smooth, I have to admit though that I tested with demo content on a site still under development.

As for default_content it does use YAML, but it has a different scope (to provide default content, not to import/export content).
tome_sync has an overlapping scope with default_content_deploy, but I find tome more straightforward :)

mxr576’s picture

Also just saw that https://www.drupal.org/project/default_content uses Yaml as of 2.0 - our modules have a lot of overlap lol!

But this is an actively maintained solution ;)

  • samuel.mortenson authored 3eae6fa on 8.x-1.x
    Issue #2980848 by samuel.mortenson, larowlan, bserem: Add YAML as an...
samuel.mortenson’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all, let's ship it! I'll do a release this month.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.