We're in need of a content entity import/export mechanism for Commerce, so I decided to look at the existing solutions (default_content, yaml_content, demo_content).

My own expectation of the export flow is something like this:
1) Entity is exported to an array ($entity->toArray())
2) Field data is normalized based on the field type
3) The final structure is exported into YAML
And import is the reverse.

This is precisely the use case for the core Serialization module. It has a normalizer architecture, and encoders.
The normalizer architecture is unpleasant (due to the way its tied to the format), but that's a well documented complaint (#2575761: Discuss a better system for discovering and selecting normalizers).
No YAML encoder exists in core, but one could easily be provided.

So, looking at the module, I was surprised to see it relying on HAL, one level above the Serialization module.
The information added by HAL (_links) seems to be pure noise for the import/export use case. Furthermore, it's JSON, which doesn't match the default config YAML. Is this decision documented somewhere? Or was it done purely from a code reuse perspective?

Comments

bojanz created an issue. See original summary.

larowlan’s picture

Status: Active » Needs review

Hey Bojanz

1) We used hal over serialization because of reverse references. At the time this module was created, serialization module didn't reverse resolve entity-references by UUID on denormalize. It now does, so in theory we could support both.
2) YAML encoder support was abandoned in core on security grounds - see #1897612: Add YAML support to serialization module

For some of the background on how and when this came about, see the original post https://www.previousnext.com.au/blog/potential-default-content-solution-... - it discusses a lot of these points.

Lee

Wim Leers’s picture

bojanz’s picture

Status: Needs review » Fixed

Sorry for the late followup here.

That explanation makes sense. I see that the YAML security issue has been fixed in the meantime, which means that that it might be possible to experiment with a YAML serializer + additonal normalizers, if not in this branch then in a potential 8.x-2.x. Of course, it is purely cosmetic, but it seems that the YAML vs JSON+HAL difference was enough of a reason for competing modules to be built.
I'll keep it on my list of topics for rainy day explorations.

Thank you for your efforts.

Wim Leers’s picture

Issue tags: +API-First Initiative

Status: Fixed » Closed (fixed)

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