Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

Views Simple Math Field

Security covered

Part of the Views ecosystem · 211 projects

View on drupal.org

Based on https://www.drupal.org/project/views_cumulative_field, this module allows you to perform simple math expressions on two Views fields.

I created this because Drupal 8 Ctools does not currently have the Global Math Expression field that it had in Drupal 7.

Note: Twig can do math, but it's better to do math with PHP. This field is especially useful for site-builders who want to avoid Twig or who have a module like Charts that responds better to this module than a field rewrite.

Instructions

After you enable this module (you may need to run cron/clear caches):

  1. Create/edit your view.
  2. Add fields as values on which you will perform your operation.
  3. Add the "Global: Simple Math Field" field (created by this module).
  4. Select the fields, and then add their tokens (e.g. @field_one) into the text area. An example operation could be '(@field_one / @field_two) * 100'.

That's it!

Versions

8.x-2.x

This version allows users to add multiple fields and operations into the same formula. It makes use of the "Eval-math" library. There is currently no upgrade path from 1.x to 2.x, but it's relatively easy to re-configure existing Views Simple Math Fields once you have updated (edit the view, configure the field, save). Would love someone to contribute an upgrade path! Here's what the 2.x field looks like:

3.0.x

This is nearly identical to 8.x-2.x, except it now relies on a fork of the "Eval-math" library to accommodate PHP 8+.

Contributing

If you are interested in helping out with this module, please submit patches or contact me directly.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Jun 2024
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
3.0.2 Stable Jun 26, 2024