Preparing Drupal Entity Data for Views with Entity Malfunction
Drupal views are superb at sorting, filtering and formatting content, but they work with the values sitting in the database. When a listing needs something nobody typed into a field — a delivery estimate, a membership renewal flag, a fallback display name — the usual answers are custom code, a rewrite inside the View, or a computed field saved alongside the content. Entity Malfunction, a contributed module, offers a fourth path: it attaches rules to entity types and prepares entity data as it is loaded so a View has a ready value to show.
The idea is quick to grasp and flexible enough to run a council service site or a national membership directory. A malfunction pairs conditions with alterations: when an article carries a particular taxonomy term, or belongs to a particular bundle, a chosen property or field is set, emptied or copied from somewhere else. The change happens in memory during the request, so stored content stays exactly as an editor left it while the listing shows the prepared value.
What follows covers installing the module, building a first malfunction, attaching conditions that mirror real editorial rules, and wiring the result into a Views configuration. It also looks at Australian contexts where derived listing values matter: capital city time zones, GST-inclusive pricing under the Australian Consumer Law, Australia Post shipping zones, and consent wording on membership forms under the Spam Act 2003.
What Entity Malfunction changes at load time
Entity Malfunction hooks into the entity lifecycle and applies its alterations to the entity object as that object is built, before a View renders it. Anything reading the entity afterwards — a field formatter, a Views row plugin, a token inside a paragraph — sees the adjusted value. That is the difference between this module and a Views-only trick: the prepared data is attached to the entity rather than to one particular display.
Most releases let you target any exposed property: a field value, the entity label, the status flag, or a numeric base property such as the author id. Alteration types include setting a fixed value, emptying a property, copying a value from another field, and replacing values on a multi-value field. The exact plugin set has grown across releases, so read the project documentation for the version you install.
One point deserves emphasis. Because the change happens at load time rather than save time, the database keeps the original data. If other code loads an entity and then saves it, a prepared value can be written back unintentionally. Treat malfunctions as a display layer and keep editing code away from entities that carry them.
Installing the module and its supporting parts
Install Entity Malfunction with Composer and enable it like any contributed module: composer require drupal/entity_malfunction, then drush en entity_malfunction or the Extension page check. Views is what you need on the listing side, and the module's own field type only appears in the Views interface once Views is present. Check the project page for the Drupal 10 and 11 status of the release you are about to use.
Permissions arrive with the module. The administrative permission that allows creating and editing malfunctions belongs with a small group of trusted builders, not with the content editors publishing articles every day. Malfunctions are configuration, so they export to YAML with the rest of your site configuration — useful when moving from a local build to a council's staging environment or a client's production server.
Plan your cache strategy early. Every alteration is evaluated each time the relevant entity loads, and rendered View output is often stored in the render cache or entity query cache. After adding or changing a malfunction, clear those caches, or stale prepared values will linger in the listing.
Building a malfunction step by step
Open the module's administrative page — in most releases it sits in the Structure menu — and create a new malfunction. Give it a label and a machine name describing the editorial rule rather than the field it touches, something like council_collection_badge instead of field_badge. Then choose the entity type and bundle the rule applies to, for example Node and Article, or Content and Event.
Next come conditions and alterations. A condition narrows when the rule fires: a taxonomy term attached to the node, a bundle, a comparison on a field value, the viewing user's role, the current path, or the content language. An alteration names the target property and what happens to it — set it to a fixed string, empty it so a fallback takes over, copy the value from a different field, or replace it with a calculated value. These appear as plugins, so screen wording depends on your version.
Test the rule against real content. Open a node that satisfies the condition and one that does not, then compare what a View shows. The Devel module is worth enabling in a development environment: it lets you inspect the entity array before and after rendering and confirm the property really changed rather than being shadowed by a formatter. Once the behaviour is right, add the field to a View and check it there, since a malfunction working in isolation can still be hidden by a display setting in the View itself.
Conditions that reflect real editorial rules
Conditions are where a malfunction becomes useful rather than decorative. A single rule can look for a content type, a taxonomy term, a value range in a date field, or the presence of a term in a multi-value field. When several conditions sit on one malfunction they normally combine as AND, and where your version supports nested groups you can express combinations such as "tagged either Council or Community".
Role and path conditions deserve particular care. A rule firing for authenticated staff can prepare a different value in a staff-facing listing: hide an internal reference number, expose an editorial note, or set a fallback label. These conditions are evaluated against the user viewing the page, which is what a membership directory or staff-only event calendar needs. The flip side is caching — a render cached for an anonymous visitor should not be reused for a logged-in user, so configure the View's caching accordingly.
Keep condition logic cheap. Each comparison runs per entity load, so a rule checking four fields against four vocabularies adds up across a pager of fifty results. Prefer one taxonomy term over a stack of field checks, and remember that conditions do not change the query the View runs — they only shape what happens afterwards.
Surfacing altered values in a Views listing
A View can show prepared values in two ways. Add fields from the content type as usual and the field formatters read from the loaded entity, so an altered property renders with its new value. The module also registers its own field type that can display the result of a named malfunction, useful when you want a column labelled with the rule rather than the underlying field name — a "Status" column reading from a malfunction instead of the raw workflow field.
There is a limit worth understanding before you plan a build around derived values. Views filters and sorts on an entity type operate at the database level, so they see stored values, not values prepared at load time. If a listing must be filtered by "renewal due within 30 days", a runtime alteration will not make that filter work. Use a stored computed field for anything queryable, and reserve Entity Malfunction for display values, fallbacks and context-dependent labels.
Display choices still matter. A prepared value that reads well on a wide desktop screen can be unreadable on the phone most Australians use through the day, so check a mobile preview of the View. Decide too whether the View renders full entities or a compact field set: a listing of waste collection dates for a Melbourne suburb wants six narrow columns, while a listing of news articles can afford a rendered teaser.
Australian site scenarios worth copying
Time zones make a natural first example. A national organisation running events across Sydney, Melbourne, Brisbane and Perth has four local clock times, and a listing of upcoming sessions often needs the venue's local time rather than the site's default. A malfunction keyed on a venue field can prepare a formatted date with the right zone abbreviation, and a second rule can flag an event starting within 24 hours. The same pattern suits a council's kerbside collection schedule, where residents checking their bin day on a phone during the morning run want to know whether collection happens today.
Pricing rules give the module a commercial use. Under the Australian Consumer Law, prices shown to consumers must be clear and not misleading, and Australian retail practice is to display GST-inclusive amounts. Where a price field holds a bare number, a malfunction can prepare a display string noting that GST is included, along with a delivery estimate derived from an Australia Post shipping zone field, so a View column reads properly without every product being re-saved.
Consent and privacy wording is a third area. Membership forms and contact blocks often need a distinction between a public contact channel and a private one, and the Spam Act 2003 sets strict expectations for commercial email. A malfunction can prepare a contact label such as "Membership enquiries" with the right reply-to address for a specific role, or set a fallback display name when a trading name field is empty. None of this replaces a privacy statement meeting the Australian Privacy Principles under the Privacy Act 1988, but it keeps the listing honest about what a member chose to publish.
Practical recommendations for a stable configuration
Treat the first malfunction as a proof of concept: one bundle, one condition, one alteration, tested against a copy of the View you actually use. Expand from there, keeping each rule small enough to explain in a sentence during a handover.
- Start with a single bundle and a single condition, then widen the rule once the behaviour is trusted.
- Name every malfunction after the editorial rule it expresses, so the admin list reads as documentation.
- Export the configuration to YAML and deploy it like any other site configuration, rather than relying on one developer's database.
- Choose a stored computed field whenever a derived value must be filtered, sorted or exported; use runtime preparation for display and fallbacks.
- Clear render and entity caches after every change, and test on a non-production View before switching a live listing over.
- Restrict the module's administrative permission to trusted builders, and record who owns each rule.
Weighing the options side by side:
| Approach | What it changes | Suits | Limitation |
|---|---|---|---|
| Entity Malfunction | Entity data as it loads | Prepared display values, fallbacks, context-dependent labels | Runtime only, so unusable in database-level filters and sorts |
| Computed Field module | Stored field value recalculated on save | Derived values that must be queryable, sortable or exportable | Requires recalculation logic and storage per bundle |
| Views field rewrite | The rendered output of one View | Quick labels and small formatting changes | Repeated for every View, with no reusable rule set |
| hook_entity_view_alter or preprocess | Markup at render time | Fine-grained output tweaks | Tied to a display and skipped by some View formats |
| Template overrides | Full markup control | Unique layouts with bespoke classes | Heavy maintenance and awkward for editors |
Entity Malfunction earns its place when a derived value is presentational, conditional or a fallback, and a stored computed field earns its place when the value has to travel through a query, an export or a search index. A hybrid is common on real projects: computed fields carry the queryable numbers, malfunctions carry the display strings, and the View configuration decides which columns the public sees.