Computed Field is a very powerful field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define in PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) This field is literally the Swiss Army knife of fields. So start cooking up your PHP based values!

Versions

The module has undergone considerable evolution and the various version differ in their approach.

Version 4 (Drupal 9 and higher)

The values of computed fields are generated by plugins.

Computed fields on entities can be either:

  • Created in the admin UI, similarly to normal stored fields
  • Automatically created by the definition of the computed field plugin

Computed fields can use the same field formatters as normal stored fields, according to their data type.

There is no upgrade path from version 3.

Long term planning: see the #3342878: Version 4 roadmap. Any feedback and/or patches would be appreciated.

Version 3 (Drupal 8 & 9 and higher)

Computed field values are returned by a hook that must be implemented in custom code.

You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views. (Although you should note that Views use requires database stored values.)

Long term planning: see the #3143864: Version 3 (3.x) roadmap. Any feedback and/or patches would be appreciated.

Version 2 (Drupal 8)

Computed field values are returned by a hook that must be implemented in custom code, or can be entered in the admin UI as PHP code.

There is no upgrade path from D7 or D6.

Version 7.x-1.x (Drupal 7 and older)

  • There is no upgrade path from D6. It would likely be tricky given the new DB Abstraction Layer and the new Fields API.
  • The variables used for computation have changed because D7 now has fields and i18n support in core. The new variables are noted on the field forms, but be aware that they are different from D6!
  • Because D7 now has fields in core, Computed Fields can now be attached to other entities (e.g. users, taxonomy terms). If there are any problems with this report over at #1262724: Generic entity support.
  • There is initial Views support, but more work needs to be done.
  • There is initial suport for Locale/i18n that's in D7 core.

Security Warning

This only applies to Drupal 8 and lower as PHP can no longer be provided on the front-end. This insecure feature has been removed in Drupal 9+.

This module is intended to be used by PHP developers to insert & execute PHP code on a Drupal website. It does not provide a macro interface, a code builder or anything other than insert your working code here into this text area. You need to have a good working knowledge of PHP and the Drupal API to use this module. To get the best results with this module, pre-test your PHP code in the Body field of a Page in Drupal.

Note that entering PHP code into the database is not recommended, as it is a security risk if someone is able to bypass access controls on the Web front-end. Additionally, the code is also not version controlled, and any mistakes can take down the site.

The recommended approach is to implement the provided hooks in custom modules. If you're not doing this, expect problems. You've been warned!

Support

Please do not post questions to the issue queue asking for unpaid help with your specific PHP code snippet. They will generally be ignored or closed. Use Computed Field code snippets for code examples and seeking assistance. If you have another useful (or instructive) example please add it to the manual pages, and if you'd like to help with support, please answer support questions over there.

If you are looking for paid support, you may post a support request in the issue queue marked as such. These may be picked up by anybody, as the current maintainers don't have time to work on such issues.

Documentation

To get started, make sure to follow the documentation link to the right.

General Branch Notes

Note: The "master" GIT branch for this project is not actively used, but we can't delete it. We've tried, and received the following error:

The branch master is tied to a development release on Drupal.org, and cannot be deleted.

So we navigated to that release, and tried to delete, but there was no means by which to do so. If anyone cares enough about this, please open an issue with the Web team.

Alternatives

Supporting organizations: 
Drupal 8 & 9 maintenance

Project information

Releases