Overview
This module creates a new duration field, that can be added to any entity. A duration field can collect any combination of year, month, day, hour, minute and second. Field settings allow for the site builder to determine what level of granularity they wish to collect from users, so if the required level of granularity is a date, the field settings would be set to collect year, month and day. The module is flexible in that users could choose to only collect year and seconds. While this doesn't really make sense for most logical data collection, the module has the flexibility that allows it to happen.
Verson 8.x-2.x
Version 2 of the module has been released. As of 8.x-2.0-rc1, there is an upgrade path between version 8.x-1.x and 8.x-2.x of the module. To update:
- Take a backup of your database
- Run update.php
Version 2.x of the module is a fairly significant re-write, that ensures it works with Drupal core APIs, including the Typed Data API, the Form Element API, the Field API, and the Constraint API. It is the recommended version at this point for new installations of the module. This version is ready to go, and all the automated tests from version 1 are working, so the module should work fine.
Technical Overview
Version 8.x-2.x of the module fully integrates with Drupal APIs at a deep technical level. The module creates:
- A new Typed Data type: Date Interval. This data type is a wrapper for PHP DateInterval objects.
- A new Typed Data type: Granularity String. This data type is used to store granularity strings. For specifics on what a granularity string is, see Drupal\duration_field\Plugin\DataType\GranularityStringData.
- A new Typed Data type: ISO 8601 Duration String. This data type is used to store ISO 8601 duration strings.
- A new form element: duration. This form element takes in 8601 Duration Strings or PHP DateInterval objects as its value/default value, and outputs PHP DateInterval objects upon form submission. The form element collects year, month, day, hour, minute and seconds, and by passing the #granularity, the developer can select which time elements should be included.
- A new form element: granularity. This form element takes in a granularity string as value/default value. The element provides checkboxes for year, month, day, hour, minute, and second, and outputs a granularity sting upon form submission.
- Validation constraints for date intervals, ISO 8601 duration strings, and granularity strings.
Project information
- Module categories: Site structure
- 3,725 sites report using this module
- Created by jaypan on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Drupal 10 compatibility and bugfixes
Development version: 8.x-2.x-dev updated 10 Sep 2024 at 14:38 UTC