From d3d09f56ca6b7b469336da7a8006f74b73050d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Sun, 29 Sep 2019 10:19:41 -0400 Subject: [PATCH] Document corrected (not assuming a single value field) check for GEO Original term Ref #10 --- web/modules/custom/geo_citation/geo_citation.module | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/modules/custom/geo_citation/geo_citation.module b/web/modules/custom/geo_citation/geo_citation.module index ec35b2d..3125819 100644 --- a/web/modules/custom/geo_citation/geo_citation.module +++ b/web/modules/custom/geo_citation/geo_citation.module @@ -63,9 +63,15 @@ function geo_citation_theme($existing, $type, $theme, $path) { */ function geo_citation_pseudo_field($entity) { $markup = ''; - $article_type = $entity->field_article_type->getValue(); - // If it's not a GEO Original article, there's nothing for us to do. - if (!isset($article_type[0]) || $article_type[0]['target_id'] != '303') { + + // This returns a numerically-indexed array of arrays with little in them + // except the taxonomy term 'target_id' as a stringified number. + $article_types = $entity->field_article_type->getValue(); + // This looks for the index matching 'GEO Original' (term ID 303), which will + // often be zero when it's the only selected article type, so we must be sure + // to test for a false identity and not accidentally reject zero. + if (array_search('303', array_column($article_types, 'target_id')) === FALSE) { + // If it's not a GEO Original article, we do not add a citation. return $markup; }