Time for action – developing custom field formatter

Let's open the recipe page we created just before developing our custom module. On our recipe page which we created using our custom content type, all time fields (cookTime and prepTime) values are displayed in minutes, for example, 60 minutes and 90 minutes. It would be nice if 60 minutes was displayed as 1 hour and 90 minutes was displayed as 1 1⁄2 hours.

One way we can make this happen is to develop a custom module to create a custom field formatter that will display the duration related fields of cookTime and prepTime as hours instead of minutes.

Following are the basic steps involved in creating a new plugin or creating a custom field formatter:

  1. Create the custom formatter class. This class ...

Get Drupal 8 Development Beginner's Guide - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.