Document corrected (not assuming a single value field) check for GEO Original term

Ref #10
This commit is contained in:
benjamin melançon 2019-09-29 10:19:41 -04:00
parent a984702fc0
commit d3d09f56ca

View file

@ -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;
}