Custom display suite fields in Drupal 8

Kevin howbrook
Apr 21, 2017 · 1 min read

One of the most useful modules in Drupal is display suite. Something I constantly use, especially for creating custom display fields.

What’s a custom display field?

It’s purely a field for rendering specific content on the display. No field api work, we just want to get some information related to the node and display it in a display suite template

Why would I need to use a custom display field?

The short answer is you’ll always need to do something like override a node or field template, and usually that’s enough. But sometimes you need a bit more, that’s where display suite fields come in. Let’s say for example we wanted to display a nodes published date and the author like this:

28 November 2016 by FoxMulder

We could display the fields next to each other, and let the themer handle it, but that’s not that nice. We could also just do this in the node template, but what if I want this on multiple view modes? I would have to override the template for each one. Plus, with this configuration being in code, it’s a bit nicer to handle.

Here is an example custom module to show you a very basic field showing our date and author.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store