From 8316258805937b9c852dc4c6935a05d35a08d580 Mon Sep 17 00:00:00 2001 From: James White Date: Sun, 29 Dec 2024 12:55:42 +0000 Subject: [PATCH] Add time field parsing --- src/fields/Time.php | 65 ++++++++++++++++++++++++ src/services/Fields.php | 2 + src/templates/_includes/fields/time.html | 8 +++ 3 files changed, 75 insertions(+) create mode 100644 src/fields/Time.php create mode 100644 src/templates/_includes/fields/time.html diff --git a/src/fields/Time.php b/src/fields/Time.php new file mode 100644 index 00000000..7bc994f5 --- /dev/null +++ b/src/fields/Time.php @@ -0,0 +1,65 @@ +fetchValue(); + + if ($value === null) { + return null; + } + + $timeValue = DateHelper::parseTimeString($value); + + if ($timeValue) { + return $timeValue; + } + + return $value; + } +} diff --git a/src/services/Fields.php b/src/services/Fields.php index 29421cd0..11ee9643 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -38,6 +38,7 @@ use craft\feedme\fields\SuperTable; use craft\feedme\fields\Table; use craft\feedme\fields\Tags; +use craft\feedme\fields\Time; use craft\feedme\fields\TypedLink; use craft\feedme\fields\Users; use craft\helpers\Component as ComponentHelper; @@ -142,6 +143,7 @@ public function getRegisteredFields(): array RadioButtons::class, Table::class, Tags::class, + Time::class, Users::class, // Third-Party diff --git a/src/templates/_includes/fields/time.html b/src/templates/_includes/fields/time.html new file mode 100644 index 00000000..18a35dab --- /dev/null +++ b/src/templates/_includes/fields/time.html @@ -0,0 +1,8 @@ +{% import 'feed-me/_macros' as feedMeMacro %} +{% import '_includes/forms' as forms %} + +{% set default = default ?? { + type: 'time', +} %} + +{% extends 'feed-me/_includes/fields/_base' %} \ No newline at end of file