O'Reilly logo

Drupal 8 Development Beginner's Guide - Second Edition by Kurt Madel, Malabya Tewari, Rakesh James, Krishna Kanth, Edward Crompton, Samuel Keen, Tassos Koutlas, Neeraj Kumar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required