Entity Pilot - content staging for Drupal 8


  • Download and extract the module
  • Add the php-encryption library using composer or Composer manager.
    • For composer - from your Drupal installation directory run composer require "defuse/php-encryption:~1.2.
    • For Composer manager, refer to its documentation

Getting started

Changing the way Serializer handles entities

Core supports serialization for content entities, their fields, and field items. It is easy to add support for other classes, and also to modify the way Serializer handles classes.

For altering how Serializer handles a field item, one example is EntityReferenceFieldItemNormalizer. For this, they've created a class file in a module's src/Normalizer directory, which...

How the Serializer works

The Serialization API depends on Symfony's Serializer component.

Serializer's separation of concerns

The serializer splits the work into two steps. First, it will normalize the object to an array. Then it will encode that array into the requested format.

Diagram showing object transformed to array by normalize method and array transformed to string by encode

This work is split across two interfaces, the NormalizerInterface and the EncoderInterface. When a Serializer is created, all of the Normalizer objects which might be necessary to handle the data are passed in, as well as all of the relevant Encoder objects.

$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new ComplexDataNormalizer(), new ListNormalizer(), new TypedDataNormalizer());

$serializer = new Serializer($normalizers, $encoders);

Serialization API in Drupal 8

Drupal 8 can output JSON and XML versions of data using the Serialization API. Modules can add new serialization formats, as core's HAL (#1924854: [META] Hypertext Application Language (HAL) support) module will.

Serializing data

To serialize data, get the serializer from the container.

Subscribe with RSS Subscribe to RSS - serialization