Display Suite is a handy module we’ve used for a long time. However for new projects utilising Layout Builder we’ve found we don’t need it. Swap out Display Suite for Drupal 8 core blocks with contexts!
Positioning fields
The main use case for Display Suite (DS) is to position fields into layouts. However, Layout Builder now offers a Drupal 8 core alternative to building layouts.
As DS utilises core’s Layout Discovery module switching these layouts over to Layout Builder should be fairly straight forward. Having said that, so far we’ve only implemented this on new greenfield sites starting from scratch with Layout Builder.
Custom fields
One of DS’s most useful features is defining custom fields as @DsField plugins.
Say we have a custom Event entity which needs custom output to format a map of that event.
DsField version
namespace Drupalmy_eventPluginDsField;
use DrupaldsPluginDsFieldDsFieldBase;
/**
* Plugin to render a map of an event.
*
* @DsField(
* id = "my_event_map",
* ...
* entity_type = "my_event"
* )
*/
class EventMap extends DsFieldBase {
/**
* {@inheritdoc}
*/
public function build() {
/** @var Drupalmy_eventEntityEvent $event */
$event = $this->entity();
// Logic here to build and format your map utilising $event.
}
}
Block equivalent
This DsField converts directly to a Block plugin utilising context to get the entity.
namespace Drupalmy_eventPluginBlock;
use DrupalCoreBlockBlockBase;
/**
* Block implementation to render a map of an event.
*
* @Block(
* id = "my_event_map",
* ...
* context = {
* "my_event" = @ContextDefinition("entity:my_event", required = TRUE),
* }
* )
*/
class EventMap extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
/** @var Drupalmy_eventEntityEvent $event */
$event = $this->getContextValue('my_event');
// Logic here to build and format your map utilising $event.
}
}
This block is then available for placement as per the usual Layout Builder techniques.
Controlling field markup
Another use for DS is to control the markup of and around fields.
As an alternative to DS we often use Element Class Formatter module to easily inject custom classes into fields. In combination with Twig templates utilising embeds and includes this should mostly do away with the need for DS.
Summing up
DS is a great module, full kudos to swentel, aspilicious and everyone else who’s worked to make DS such a powerful UI based tool. However we don’t really see a place for it looking to a world powered by Layout Builder.
Here’s looking forward to a Drupal where all layout happens via Layout Builder!