Custom twig function and filter in Drupal 8

Twig is a part of the Symfony framework and introduced as a template engine. Drupal 8 also uses twig as a template engine.

We can modify incoming data to twig using Drupal 8 template hooks but we also need some quick filter and dynamic functions that we can directly inject to a particular template.

Drupal 8 provides a way to create custom twig extension, Let’s how we can do this.

Create custom REST Resource for GET and POST method in Drupal 8

One of the important features that are inspired by drupal 7 and imported to Drupal 8 with enhancement is its REST API. Drupal provides inbuilt Rest support for exposing entities and creating new entities. You can view all those Rest endpoints by installing the rest_ui module. However, sometimes we also need to define custom Rest Resources / Endpoints for our custom requirement.

So here is how we can define custom Rest Resources.