Drupal is a registered trademark of Dries Buytaert
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)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

physical_quantity_fields

6 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
1 month 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