Skip to content

Commit

Permalink
Merge pull request #49 from discoverygarden/FDR-398
Browse files Browse the repository at this point in the history
FDR 398: Ignore date range and other date formats
  • Loading branch information
nchiasson-dgi authored Nov 30, 2023
2 parents 36194c5 + d63179d commit d470199
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions islandora_citations.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dependencies:
- drupal:field_permissions
- drupal:node
- drupal:taxonomy
- controlled_access_terms:controlled_access_terms
configure: entity.islandora_citations.collection
14 changes: 11 additions & 3 deletions src/Normalizer/ExtendedDateTimeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -22,10 +24,16 @@ class ExtendedDateTimeNormalizer extends NormalizerBase {
public function normalize($object, $format = NULL, array $context = []) {
$dateValue = $object->getValue();
if (!empty($dateValue['value'])) {
$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 [];
}

}

0 comments on commit d470199

Please sign in to comment.