From dfab991efd6856cc5ed412987ccad32e118f0e98 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Fri, 8 Nov 2024 10:38:28 -0400 Subject: [PATCH] added orcid field formatter --- .../FieldFormatter/OrcidFieldFormatter.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Plugin/Field/FieldFormatter/OrcidFieldFormatter.php diff --git a/src/Plugin/Field/FieldFormatter/OrcidFieldFormatter.php b/src/Plugin/Field/FieldFormatter/OrcidFieldFormatter.php new file mode 100644 index 0000000..9cc0f6b --- /dev/null +++ b/src/Plugin/Field/FieldFormatter/OrcidFieldFormatter.php @@ -0,0 +1,52 @@ +t('Format string or text fields as as ORCID links.'); + return $summary; + } + + /** + * {@inheritdoc} + */ + public function viewElements(FieldItemListInterface $items, $langcode) { + $element = []; + foreach ($items as $delta => $item) { + $prefix = 'https://orcid.org/'; + // Assumes all field values are just plain text or strings values and not full orcid URLS. + $orcidUrl = $prefix . $item->value; + $imgSrc = ''; + $link = Link::fromTextAndUrl($orcidUrl, Url::fromUri($orcidUrl)); + $element[$delta] = [$link->toRenderable()]; + $element[$delta][0]['#prefix'] = $imgSrc; + } + return $element; + } +}