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