Customized API Output

Lupus Decoupled Drupal provides custom elements output for all content entities. This includes the page of a content node ("Full content"), just as the individual view-modes that may be used in content listings, e.g. teasers (Drupal allows the configuration of any number of view-modes).

A content entity can be rendered into custom elements via three methods, while the method used can be configured by view-mode. For example, when editing a content type at admin/structure/types go to the tab "Manage custom element" to configure your method.

The three methods are:

  • Custom Element Display Configuration - The typically used default method. It allows fine-grained control of the output via UI. Please see below for more details.
  • Layout builder - When enabling the "Layout Builder" module for a view-mode, the layout builder may be used to allow editors to compose pages that are displayed using custom elements. Refer to the Layout Builder guide for details.
  • Automatic processing - A method that allows taking full control of the output via PHP code, as outlined here. Activate it by ticking the "Automatic processing" checkbox in the UI.

Note: This requires the Custom Elements UI submodule, make sure it is enabled.

Custom Element Display Configuration

For each view-mode, the display configuration may be used to configure the name of the custom element used. Next, for each content field the data may be mapped to a slot or property with a configurable name:

Screenshot of custom elements UI

For each field various options are available:

  • Auto - Provides a reasonable default based upon automatic processing of the field.
  • Raw - Provides the raw Drupal field data.
  • Flattended - Instead of containing a nested object for individual data properties of a field, the output is flattended and each property gets added to the main element, prefixed by the property name. For example, a field with the data properties value and format would geth flattened to foo-value and foo-format attributes, when the name foo is configured. Note that for fields containing multiple values, only the first value is output and flattended.
  • Formatted - ...: Every Drupal field formatter rendering a field into HTML is available.
  • Custom element - Rendered entity: This is available only for entity reference fields. It's a powerful way to configure the rendering of the referenced data. The display of the selected entity and view-mode can be configured via its own "Custom Element Display Configuration". That way the output data of referenced entities can be controlled in high detail. Furthermore, by enabling the "Flatten" option the data may be flattened into the main element.

Note that the list of available options is plugin-based, and thus extendable by Drupal modules.