Overview
Entity Class Formatter is a very simple module which formats values of fields (of varying types) such that a class or attribute is placed on the parent entity of that field. The module can be used to apply classes/attributes on entities, allowing the class/attribute to act as a modifier which can be used by the theming layer.
Usage
Follow these steps
- Add a text, list, entity reference or boolean field to any entity (Node, Paragraph, Block, etc).
- Set the display to "Entity Class" (on manage display admin page).
- Create matching CSS rules in your theme or map a Modifier using the Look module.
Optional configuration
- Prefix to be attached before each class/attribute.
- Suffix to be attached after each class/attribute.
- Attribute name to be used instead of class.
- Referenced entity field name to be used instead of label.
Supported field types
This formatter can be applied to the following field types:
- Text
- List
- Entity Reference
- Boolean
Supported entity types
This formatter works with all entity types.
Similar Modules
The module is similar to two other modules, but differs in important ways.
The Classy Paragraphs module was intended to apply to Paragraphs only and is quite structured in the way classes are applied through a custom field type. The Entity Class Formatter module is more flexible in that it has been designed to apply to all entity types. It can also handle a variety of field types (text, select lists, entity references) and is able to adapt to the data at hand.
The Field Formatter CSS Class module also uses a field formatter approach to applying the class to the entity. It does have more complexity than this module because it deals with several layers of nesting. The Entity Class Formatter is very simple and only applies to the parent entity of the field.
Demo Video
Drupal Modules: The One Percent —Entity Class Formatter (tutorial) from NonProfit.
GitHub
Development is happening in our GitHub repository. The drupal.org issue queue is still used to coordinate development.
Project information
- Module categories: Content Display
- 4,696 sites report using this module
- Created by murrayw on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.