1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Hooks provided by the CDM DataPortal module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* @addtogroup hooks
|
10
|
* @{
|
11
|
*/
|
12
|
|
13
|
/**
|
14
|
* Alter the feature block list.
|
15
|
*
|
16
|
* Modules implementing this hook can add, remove or modify
|
17
|
* feature blocks of the taxon general page part and of the
|
18
|
* specimen page part.
|
19
|
*
|
20
|
* @param $block_list
|
21
|
* the array of blocks as returned by list_blocks()
|
22
|
* @param $taxon
|
23
|
* Optional CDM Taxon instance, currently only given if
|
24
|
* called from within the taxon general page part
|
25
|
*
|
26
|
* @return array
|
27
|
* the altered $block_list
|
28
|
*
|
29
|
*/
|
30
|
function hook_cdm_feature_node_blocks_alter(&$block_list, $taxon = NULL) {
|
31
|
|
32
|
if ($taxon) {
|
33
|
// taxon is only given if called from within the taxon general page part
|
34
|
$numberOfChildren = count(
|
35
|
cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON,
|
36
|
array (get_current_classification_uuid(),
|
37
|
$taxon->uuid
|
38
|
)
|
39
|
)
|
40
|
);
|
41
|
$subRank = 'sub taxa';
|
42
|
if ($taxon->name->rank->titleCache == "Genus") {
|
43
|
$subRank = "species";
|
44
|
} else if ($taxon->name->rank->titleCache == "Species") {
|
45
|
if($numberOfChildren==1){
|
46
|
$subRank = "infraspecific taxon";
|
47
|
}
|
48
|
else {
|
49
|
$subRank = "infraspecific taxa";
|
50
|
}
|
51
|
}
|
52
|
if ($numberOfChildren > 0) {
|
53
|
$block = feature_block('Number of Taxa');
|
54
|
// FIXME use compose_feature_block_wrap_elements() in next line
|
55
|
$block->content = array(markup_to_render_array(
|
56
|
'<ul class="feature-block-elements"><li>'
|
57
|
. $numberOfChildren . " " . $subRank
|
58
|
. '</li></ul>')
|
59
|
);
|
60
|
array_unshift($block_list, $block);
|
61
|
cdm_toc_list_add_item('Number of Taxa', 'number-of-taxa', NULL, TRUE);
|
62
|
}
|
63
|
}
|
64
|
|
65
|
return $block_list;
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* Alter the content of a feature block.
|
70
|
*
|
71
|
* Modules implementing this hook can add, remove or modify
|
72
|
* feature blocks contents of the taxon general page part and of the
|
73
|
* specimen page part.
|
74
|
*
|
75
|
* @param array $block_content
|
76
|
* Drupal render array for the content of the feature block
|
77
|
* @param object $feature
|
78
|
* The feature this block belongs to
|
79
|
* @param object $elements
|
80
|
* An array of CDM DescriptionElement instances which are being displayed in
|
81
|
* this block. Even if this array is passed as reference it should not being
|
82
|
* altered. Passing by reference is only recommended to reduce the memory
|
83
|
* footprint.
|
84
|
*/
|
85
|
function hook_cdm_feature_node_block_content_alter(&$block_content, $feature, &$elements){
|
86
|
if($feature->uuid == UUID_DISTRIBUTION){
|
87
|
$block_content['my_custom_render_element'] = array(
|
88
|
'#type' => 'markup',
|
89
|
'#markup' => '<h1>Hello World</h1>',
|
90
|
'#weight' => 99, // Show at the bottom of the block
|
91
|
);
|
92
|
}
|
93
|
}
|
94
|
|
95
|
/*
|
96
|
* Alter the merged feature tree for a taxon profile page.
|
97
|
*
|
98
|
* @param $merged_tree
|
99
|
* The $merged_tree as produced by merged_taxon_feature_tree($taxon)
|
100
|
* @param $taxon
|
101
|
* A CDM Taxon instance
|
102
|
*/
|
103
|
function hook_merged_taxon_feature_tree_alter($taxon, &$merged_tree){
|
104
|
|
105
|
// find the distribution feature node
|
106
|
$distribution_node =& cdm_feature_tree_find_node($merged_tree->root->childNodes, UUID_DISTRIBUTION);
|
107
|
// remove all TextData
|
108
|
$distribution_node->descriptionElements['TextData'] = array();
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* @} End of "addtogroup hooks".
|
113
|
*/
|