Compare commits
No commits in common. '30b78ce0ca86ff15117d3824384aa67fdb70f09d' and '40d0df56fd618ec7f80247d0ee5f2494578ff1bd' have entirely different histories.
30b78ce0ca
...
40d0df56fd
1 changed files with 0 additions and 53 deletions
@ -1,53 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
namespace Drupal\doi_field_formatter\Plugin\Field\FieldFormatter; |
|
||||||
|
|
||||||
use Drupal\Core\Field\FormatterBase; |
|
||||||
use Drupal\Core\Field\FieldItemListInterface; |
|
||||||
use Drupal\Core\Url; |
|
||||||
use Drupal\Core\Link; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Plugin implementation of the 'Facet_Field_Formatter' formatter. |
|
||||||
* |
|
||||||
* @FieldFormatter( |
|
||||||
* id = "orcid_text_field_formatter", |
|
||||||
* module = "doi_field_formatter", |
|
||||||
* label = @Translation("Orcid Field Formatter"), |
|
||||||
* description = @Translation("Create links to ORCID resources"), |
|
||||||
* field_types = { |
|
||||||
* "text", |
|
||||||
* "string" |
|
||||||
* } |
|
||||||
* ) |
|
||||||
*/ |
|
||||||
class OrcidFieldFormatter extends FormatterBase { |
|
||||||
|
|
||||||
/** |
|
||||||
* {@inheritdoc} |
|
||||||
*/ |
|
||||||
public function settingsSummary() { |
|
||||||
$summary = []; |
|
||||||
$summary[] = $this->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 = '<a href="'. $orcidUrl . |
|
||||||
'"><img class="orcid-id " src="https://orcid.org/sites/default/files/images/orcid_24x24.png"></a>'; |
|
||||||
$link = Link::fromTextAndUrl($orcidUrl, Url::fromUri($orcidUrl)); |
|
||||||
$element[$delta] = [$link->toRenderable()]; |
|
||||||
$element[$delta][0]['#prefix'] = $imgSrc; |
|
||||||
} |
|
||||||
return $element; |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue