From 1e88f917768df54dd6859e00683fede023353128 Mon Sep 17 00:00:00 2001 From: Akanksha Singh Date: Fri, 13 Oct 2023 17:48:37 +0530 Subject: [PATCH 1/3] FDR-398: Do not normalise EDTF date if it's a range --- src/Normalizer/ExtendedDateTimeNormalizer.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Normalizer/ExtendedDateTimeNormalizer.php b/src/Normalizer/ExtendedDateTimeNormalizer.php index 3427cba..6ed0e91 100644 --- a/src/Normalizer/ExtendedDateTimeNormalizer.php +++ b/src/Normalizer/ExtendedDateTimeNormalizer.php @@ -22,7 +22,16 @@ class ExtendedDateTimeNormalizer extends NormalizerBase { public function normalize($object, $format = NULL, array $context = []) { $dateValue = $object->getValue(); if (!empty($dateValue['value'])) { - $dateParts = explode('-', $dateValue['value']); + // Check if date is a range. We only support date at this point. + if(!preg_match('/[^a-zA-Z0-9-]+/', $dateValue['value'], $matches)) { + // Only contains dashes + $dateParts = explode('-', $dateValue['value']); + } +// else { +// // Contains special character +// // @todo support other formats such as /date, date/, date ~ etc. +// } + } return $this->formatDateVariables($dateParts ?? $dateValue); From 088fcacfac06b9650c8f59d1925e0cdc33e0e24d Mon Sep 17 00:00:00 2001 From: Akanksha Singh Date: Fri, 13 Oct 2023 17:49:43 +0530 Subject: [PATCH 2/3] FDR-398: Do not normalise EDTF date if it's a range --- src/Normalizer/ExtendedDateTimeNormalizer.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Normalizer/ExtendedDateTimeNormalizer.php b/src/Normalizer/ExtendedDateTimeNormalizer.php index 6ed0e91..05ac33d 100644 --- a/src/Normalizer/ExtendedDateTimeNormalizer.php +++ b/src/Normalizer/ExtendedDateTimeNormalizer.php @@ -23,15 +23,11 @@ public function normalize($object, $format = NULL, array $context = []) { $dateValue = $object->getValue(); if (!empty($dateValue['value'])) { // Check if date is a range. We only support date at this point. - if(!preg_match('/[^a-zA-Z0-9-]+/', $dateValue['value'], $matches)) { - // Only contains dashes + // @todo support other formats such as /date, date/, date ~ etc. + if (!preg_match('/[^a-zA-Z0-9-]+/', $dateValue['value'], $matches)) { + // Only contains dashes. $dateParts = explode('-', $dateValue['value']); } -// else { -// // Contains special character -// // @todo support other formats such as /date, date/, date ~ etc. -// } - } return $this->formatDateVariables($dateParts ?? $dateValue); From f1a9131cfeccf89a328d284a73c60ae721b45da8 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Mon, 16 Oct 2023 05:03:58 -0300 Subject: [PATCH 3/3] Use a library instead. (#51) * Use a library instead. * Add dependency on controlled_access_terms. --- composer.json | 3 ++- islandora_citations.info.yml | 1 + src/Normalizer/ExtendedDateTimeNormalizer.php | 17 ++++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 65b1912..d665cad 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "type": "drupal-module", "require": { "seboettg/citeproc-php": "^2.6.0", - "webflo/drupal-finder": "^1.2.2" + "webflo/drupal-finder": "^1.2.2", + "islandora/controlled_access_terms": "^2" } } diff --git a/islandora_citations.info.yml b/islandora_citations.info.yml index 0a6d22f..725e60c 100644 --- a/islandora_citations.info.yml +++ b/islandora_citations.info.yml @@ -7,4 +7,5 @@ dependencies: - drupal:field_permissions - drupal:node - drupal:taxonomy + - controlled_access_terms:controlled_access_terms configure: entity.islandora_citations.collection diff --git a/src/Normalizer/ExtendedDateTimeNormalizer.php b/src/Normalizer/ExtendedDateTimeNormalizer.php index 05ac33d..88591c1 100644 --- a/src/Normalizer/ExtendedDateTimeNormalizer.php +++ b/src/Normalizer/ExtendedDateTimeNormalizer.php @@ -3,6 +3,8 @@ namespace Drupal\islandora_citations\Normalizer; use Drupal\controlled_access_terms\Plugin\Field\FieldType\ExtendedDateTimeFormat; +use EDTF\EdtfFactory; +use EDTF\Model\ExtDate; /** * Converts EDTF fields to an array including computed values. @@ -22,15 +24,16 @@ class ExtendedDateTimeNormalizer extends NormalizerBase { public function normalize($object, $format = NULL, array $context = []) { $dateValue = $object->getValue(); if (!empty($dateValue['value'])) { - // Check if date is a range. We only support date at this point. - // @todo support other formats such as /date, date/, date ~ etc. - if (!preg_match('/[^a-zA-Z0-9-]+/', $dateValue['value'], $matches)) { - // Only contains dashes. - $dateParts = explode('-', $dateValue['value']); + $parser = EdtfFactory::newParser(); + $parsed = $parser->parse($dateValue['value']); + $edtf = $parsed->getEdtfValue(); + // XXX: Only support singular EDTF dates at this time, exit out if it's + // an interval or set. + if ($edtf instanceof ExtDate) { + return $this->formatDateVariables(explode('-', $edtf->iso8601())); } } - - return $this->formatDateVariables($dateParts ?? $dateValue); + return []; } }