From 9aa23c6670cdeeda1621a03a4a05c6127b37f131 Mon Sep 17 00:00:00 2001 From: Ant Brown Date: Fri, 13 Dec 2019 13:18:43 +1300 Subject: [PATCH] Check YEAR_BASE key exists before using --- .../Field/FieldFormatter/EDTFFormatter.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Plugin/Field/FieldFormatter/EDTFFormatter.php b/src/Plugin/Field/FieldFormatter/EDTFFormatter.php index 19f7f45..84915e7 100644 --- a/src/Plugin/Field/FieldFormatter/EDTFFormatter.php +++ b/src/Plugin/Field/FieldFormatter/EDTFFormatter.php @@ -216,20 +216,22 @@ protected function formatDate($edtf_text) { // Unspecified. $unspecified = []; - if (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXXX') !== FALSE) { - $unspecified[] = t('year'); - } - elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXX') !== FALSE) { - $unspecified[] = t('century'); - } - elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XX') !== FALSE) { - $unspecified[] = t('decade'); - } - elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'X') !== FALSE) { - $unspecified[] = t('year'); + if (array_key_exists(EDTFUtils::YEAR_BASE, $parsed_date)) { + if (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXXX') !== FALSE) { + $unspecified[] = t('year'); + } + elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXX') !== FALSE) { + $unspecified[] = t('century'); + } + elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XX') !== FALSE) { + $unspecified[] = t('decade'); + } + elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'X') !== FALSE) { + $unspecified[] = t('year'); + } + // Clean-up unspecified year/decade. + $year = str_replace('X', '0', $parsed_date[EDTFUtils::YEAR_BASE]); } - // Clean-up unspecified year/decade. - $year = str_replace('X', '0', $parsed_date[EDTFUtils::YEAR_BASE]); if (array_key_exists(EDTFUtils::MONTH, $parsed_date)) { if (strpos($parsed_date[EDTFUtils::MONTH], 'X') !== FALSE) {