Drupal Entity Type Behaviors for centralised settings management

Roland Obermair

Recently I came across Drupal Entity Type Behaviors (https://www.drupal.org/project/entity_type_behaviors). This module allows developers to attach settings to any entity, allowing greater flexibility in adding settings to entities.

An everyday use case is adding fields to paragraphs or content types so that an editor can choose some settings (e.g. a colour). While this is perfectly doable with a common Drupal field, this can also be quite tedious. Think of a use case where you want the same colour setting on different entities (e.g. on paragraphs vs nodes) - you will have to add the settings field to both entities, and both fields have different setting values. This approach will quickly lead to a lot of fragmentation.

With Drupal Entity Type Behaviors, you create these settings centralised in a so-called "entity behavior module". After activating that module, you can enable these new behaviors per entity basis. If things change, you go back to your module and change values etc., there in one spot.

A second benefit is the unified output of these settings: After setting everything up through entity behaviors, you can expose your settings in TWIG via a TWIG variable in a very consistent manner, making it easy to access the values while theming.


  • Drupal
  • Twig
  • Paragraphs
  • Entities

Interested in working with us? Great, contact us now!

Contact now!