Drupal is a registered trademark of Dries Buytaert
cms 2.1.3 Update released for Drupal core (2.1.3)! drupal 10.5.11 Update released for Drupal core (10.5.11)! drupal 11.3.11 Update released for Drupal core (11.3.11)! drupal 11.2.13 Update released for Drupal core (11.2.13)! drupal 10.6.10 Update released for Drupal core (10.6.10)! cms 2.1.2 Update released for Drupal core (2.1.2)! drupal 11.1.10 Update released for Drupal core (11.1.10)! drupal 10.5.10 Update released for Drupal core (10.5.10)! drupal 10.4.10 Update released for Drupal core (10.4.10)! drupal 11.2.12 Update released for Drupal core (11.2.12)! drupal 11.3.10 Update released for Drupal core (11.3.10)! drupal 10.6.9 Update released for Drupal core (10.6.9)! drupal 10.6.8 Update released for Drupal core (10.6.8)! drupal 11.3.9 Update released for Drupal core (11.3.9)! drupal 11.3.8 Update released for Drupal core (11.3.8)! drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)!

physical_quantity_fields

5 sites No security coverage
View on drupal.org

The Physical Quantity Fields module for Drupal 10/11 is a robust engineering and scientific toolkit that provides 15+ specialized field types for physical measurements. Built with a service-based architecture and NIST-sourced conversion factors, it ensures high-precision data storage and flexible display options for everything from microscopic lengths to astronomical distances.

Key Features

  • 15 Specialized Field Types: Comprehensive support for Length, Mass, Temperature, Volume, Time, Speed, Area, Pressure, Energy, Power, Angle, and Data Storage.
  • Scientific Precision: Utilizes NIST-sourced conversion factors and mathematically correct formulaic temperature conversions (Celsius, Fahrenheit, Kelvin, etc.) to maintain round-trip accuracy.
  • Granular Formatter Control: Customize displays with 0–10 decimal precision, prefix/suffix toggles, text transformations (UPPERCASE/Title Case), and trailing dot options for abbreviations.
  • Developer-First Architecture: Logic is centralized in the UnitConverter service. Easily inject conversion capabilities into your own custom modules or services.
  • Themeable Output: Includes built-in Twig template suggestions (e.g., physical-quantity--length.html.twig) for effortless per-type styling.
  • Legacy Compatible: Fully backward compatible with 1.x data. Includes automated configuration migrations for a seamless upgrade path.

Installation

Install the module via Composer to automatically handle class mapping and service registration:

composer require drupal/physical_quantity_fields

Enable the module using Drush:

drush en physical_quantity_fields

Configuration & Usage

Once enabled, physical quantity fields can be added to any fieldable entity (Nodes, Users, Media, etc.):

  1. Navigate to Structure » Content types » [Your Type] » Manage fields.
  2. Click Add field and select a quantity type (e.g., Mass or Energy).
  3. In Manage form display, configure unit-label suffixes and min/max validation constraints.
  4. In Manage display, choose your target display unit. The module handles the conversion from the stored base unit automatically.

Developer API

For developers needing to perform conversions in code, the physical_quantity_fields.unit_converter service provides a clean interface:

// Convert 100 Kilometers to Miles
$miles = $unitConverter->convert(100.0, 'km', 'mi', 'length');

Requirements

  • Drupal: 10.2+ or 11.x
  • PHP: 8.1+
  • Core Module: Field

Similar Projects

Supporting this Module

The Physical Quantity Fields module is maintained to provide the Drupal community with a reliable standard for measurement data. You can help improve the project:

  • Bug Reports: Report accuracy issues or UI bugs in the Issue Queue.
  • New Units: Suggest additional units or quantity types (e.g., Luminosity or Frequency) via a feature request.
  • Testing: The module includes Unit, Kernel, and Functional tests. Contributions to test coverage are always welcome!

Activity

Total releases
5
First release
Feb 2025
Latest release
2 months ago
Release cadence
99 days
Stability
60% stable

Release Timeline

Releases

Version Type Release date
2.0.0 Stable Mar 3, 2026
2.0.x-dev Dev Mar 2, 2026
1.3.x-dev Dev Feb 2, 2025
1.3.1 Stable Feb 2, 2025
1.2.3 Stable Feb 2, 2025