Using Normalizers to Alter REST JSON Structure in Drupal 8

Overview

Drupal 8 core provides for solid REST capabilities out-of-the-box, which is great for integrating with a web service or allowing a third-party application to consume content. However, the REST output provided by Drupal core is in a certain structure that may not necessarily satisfy the requirements as per the structure the consuming application expects.

In comes normalizers that will help us alter the REST response to our liking. For this example, we will be looking at altering the JSON response for node entities.
 

Flag Migrations in Drupal 8

There is no explicit documentation for the Drupal 8 version of the flag module, and now that the Drupal 8 version has hit alpha, it's a good time to share some information on it.

In Drupal 8, migration destinations are easy to set up for entities. Since flags are entities in Drupal 8, all you need to do is set up a standard entity migration configuration with the fields for creating a flag.
 

The fields are:

flag_id - The flag's bundle machine name in Drupal

Migration with Custom Values in Drupal 8

Custom Preprocessing

In Drupal 7 there were numerous ways to preprocess data prior to migrating values. This was especially useful when inconsistencies in the data source needed to be addressed. One example I have dealt with in the past was migrating email addresses from an old system that didn’t check for properly formatted emails on its user fields. These errors would produce faulty data in the new Drupal site. I preprocessed the field data for the most common mistakes which reduced the amount of erroneous addresses brought over.

How to Fix a Testbot Bug When Adding New Tests

It's pretty well known that manually testing software changes is better than not testing changes at all, but it's even better to have a set of code tests that can be run automatically. In the Drupal world, this means writing tests using the Simpletest APIs, or on Drupal 8, PHPUnit. Having tests in code will mean that any time someone uploads a patch the drupal.org automated systems will kick in and, hopefully, confirm there are no regressions (i.e. bugs) from the proposed changes in the patch.

Adding Custom Styles and Classes to Your WYSIWYG

More and more these days, we need to add custom styles to content that the user enters. This can be a challenge for front end developers as we don't know how the information will be entered and have less control over the structure. One thing we can do to help content editors is to provide them with classes and styles based on these classes that they can add in the WYSIWYG.

As this is not a how to set up a WYSIWYG tutorial, I will just state that we use CKEditor.

Once CKEditor is installed, you can begin configuring it and adding your own styles and functionality.