Adding new formats

Core supports JSON and XML, as well as HAL-JSON. It is easy to add support for other formats.

Adding basic support

As explained in How the Serializer works, the serialization process has two parts, normalization and encoding.

If the array structure created by core's default Normalizers is acceptable for your format, then you can simply add an Encoder. For example, this is how support for YAML is added to core.

  1. Create an encoder
    Your Encoder should implement EncoderInterface.
  2. Register the encoder with the container
    Any service added to the container which is tagged with 'encoder' will be added to the encoder array which is passed into the Serializer. This code is placed in your module's Bundle class in the build() method.
    $container->register('serializer.encoder.yaml', 'Drupal\Core\Serialization\YamlEncoder')
      ->addTag('encoder');

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.

--To be completed--

How do I show the Login block on my homepage of my site!?

I want it on the homepage of the site, I already know how to login, the example.com/user kinda thing,
I tried setting the permissions for the user block to show, that didn't work, I tried moving the box around using the block manager thing in the "Structure" bar, but that didn't work. Please help me get the login box viewable for all users again! PLEASE HELP!

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.

New to Drupal

Hi,
I would like to know if any of you guys have seen a price comaprison page made with drupal?
Second do you have some similar example pages? would you provide me the link?
cheers !!

Pages

Subscribe with RSS Subscribe to RSS - Drupal 8.x