Skip to main content
Joachim's blog

Main navigation

  • Home
  • About
  • Hire me

Breadcrumb

  1. Home

Field API

By joachim, Sun, 05/07/2026 - 16:02

No data, no problem: computed fields made simple

It's often useful to let the machines do the work, and output something that's dynamically computed on an entity. By that I mean something that can't be hardcoded as a fixed value for all entities of a particular type, but that varies for each entity, in a way that allows it to be generated in code rather than laboriously entered into each entity form by humans.

For example, you might want a backlink for an entity reference, or a link to a view that has an argument for the entity's ID, or something that depends on field values on the entity.

Tags

  • Field API
  • Drupal core
By joachim, Mon, 31/01/2022 - 17:14

Defining bundle fields in code

Fields in Drupal 9 can be defined in code, or they can be defined in configuration. Both techniques have their uses and advantages. Typically code fields apply to all bundles of the entity type, as so-called base fields, while config fields apply only to a single bundle.

But there is a way to have code fields which apply only to specific bundles: these are called bundle fields. These are particularly useful for adding computed fields to specific bundles of an entity (more on computed fields in a future blog post).

Tags

  • Entity API
  • Field API
  • Drupal core
By joachim, Thu, 19/03/2020 - 14:07

Base fields versus config fields, and how to handle the latter in tests

All fields are equal in Drupal 8! Back in Drupal 7 we had two different systems for data on entities, which worked fairly differently: entity properties that were defined as database fields and controlled by hardcoded form elements, and user-created fields on entities that had widgets and formatters. But now in Drupal 8, every value on an entity is a field, with the same configuration in the UI, access to the widgets and formatters, and whose data is accessed in the same way.

Tags

  • tests
  • Field API
By joachim, Mon, 16/01/2017 - 22:22

Changing the type of a node

There’s an old saying that no information architecture survives contact with the user. Or something like that. You’ll carefully design and build your content types and taxonomies, and then find that the users are actually not quite using what you’ve built in quite the way it was intended when you were building it.

And so there comes a point where you need to grit your teeth, change the structure of the site’s content, and convert existing content.

Tags

  • Field API
Field API

Frequent tags

  • Drupal Code Builder (9)
  • module builder (7)
  • git (7)
  • 6.x (5)
  • Drupal core (5)
  • drupal commerce (4)
  • Field API (4)
  • contributing code (3)
  • Drush (3)
  • Entity API (3)
  • tests (3)
  • development (3)
  • patching (3)
  • Rector (3)
  • Composer (3)
  • roadmap (2)
  • contrib module (2)
  • maintaining projects (2)
  • drupal.org (2)
  • debugging (2)
  • code style (2)
  • deprecation (2)
  • 7.x (2)
  • issue queue (2)
  • multisite (2)
  • wtf (2)
  • developer tools (2)
  • modules (2)
Powered by Drupal