Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Physical Quantity Fields

3 sites No security coverage Drupal 10–11
View on drupal.org

This module provides specialized field types for storing and displaying various physical measurements, ensuring scientific precision with NIST-sourced conversion factors. It offers granular control over how these measurements are displayed and an easy-to-use developer API for programmatic conversions.

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!

Depends on

Dependencies of the latest stable release

  • field Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
5
Tracked since
Feb 2025
Latest release
5 months ago
Releases (12 mo)
2 ▼ from 3
Maintenance
Active

Release Timeline

Releases

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