-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_herbarium_object.module
78 lines (70 loc) · 1.99 KB
/
islandora_herbarium_object.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* @file
* Contains islandora_herbarium.module.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function islandora_herbarium_object_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the islandora_pdf module.
case 'help.page.islandora_herbarium':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Islandora Herbarium') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_rdf_namespaces().
*/
function islandora_herbarium_object_rdf_namespaces() {
// Yes, it's amazing, rdf is not registered by default!
return [
'dwc' => 'http://rs.tdwg.org/dwc/terms/',
'dwciri' => 'http://rs.tdwg.org/dwc/iri/',
];
}
/**
* Implements hook_theme().
*/
function islandora_herbarium_object_theme($existing, $type, $theme, $path) {
return [
'fdg_graph' => [
'variables' => ['height' => NULL, 'width' => NULL],
],
];
}
/**
* Implements hook_entity_presave().
*/
function islandora_herbarium_object_entity_presave(EntityInterface $entity) {
if ($entity->bundle() == 'islandora_herbarium_object') {
// Get the geo data.
try {
$geo = \Drupal::service('islandora_herbarium_object.geoparser');
$geo->updateEntity($entity);
}
catch (Exception $e) {
\Drupal::messenger()->addError(t('There was an error retrieving Geo data. %msg.',
['%msg' => $e->getMessage()]));
}
// Get the taxonomy data.
try {
$taxon = \Drupal::service('islandora_herbarium_object.taxonparser');
$taxon->updateEntity($entity);
}
catch (Exception $e) {
\Drupal::messenger()->addError(t('There was an error retrieving Taxon data. %msg.',
['%msg' => $e->getMessage()]));
}
$title = $entity->get('field_dwc_scientificname')->value . ' - ' . $geo->getValue('name');
if ($title != ' - ') {
$entity->setTitle($title);
}
}
}