diff --git a/src/Plugin/Field/FieldFormatter/FdgGraphTextFieldFormatter.php b/src/Plugin/Field/FieldFormatter/FdgGraphTextFieldFormatter.php new file mode 100644 index 0000000..066c318 --- /dev/null +++ b/src/Plugin/Field/FieldFormatter/FdgGraphTextFieldFormatter.php @@ -0,0 +1,58 @@ +t('Format string or text fields as links to a FDG Graph. ' + . 'Only useful for Scientific Name or Municipalty fields'); + return $summary; + } + + /** + * {@inheritdoc} + */ + public function viewElements(FieldItemListInterface $items, $langcode) { + $element = []; + + foreach ($items as $delta => $item) { + $field = $item->getFieldDefinition(); + // TODO: more robust fieldname parsing + $fieldLabel = str_replace(' ', '_', $field->getLabel()); + $municipality = ($fieldLabel == 'Municipality') ? $item->value : 'NULL'; + $scientificName = ($fieldLabel == 'Scientific_Name') ? $item->value : 'NULL'; + $link = Link::fromTextAndUrl($item->value, Url::fromroute('islandora_herbarium_object.graph', + ['scientificName' => $scientificName, 'municipality' => $municipality])); + $element[$delta] = [$link->toRenderable()]; + } + + return $element; + } +}