1 |
5189a8ec
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Hooks provided by the CDM DataPortal module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* @addtogroup hooks
|
10 |
|
|
* @{
|
11 |
|
|
*/
|
12 |
|
|
|
13 |
9aff46e4
|
Andreas Kohlbecker
|
/**
|
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 |
bdd382be
|
Andreas Kohlbecker
|
function hook_cdm_feature_node_blocks_alter(&$block_list, $taxon = NULL) {
|
31 |
9aff46e4
|
Andreas Kohlbecker
|
|
32 |
bdd382be
|
Andreas Kohlbecker
|
if ($taxon) {
|
33 |
|
|
// taxon is only given if called from within the taxon general page part
|
34 |
f78fda81
|
Andreas Kohlbecker
|
$numberOfChildren = count(
|
35 |
|
|
cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON,
|
36 |
7663cd0b
|
Andreas Kohlbecker
|
array (get_current_classification_uuid(),
|
37 |
f78fda81
|
Andreas Kohlbecker
|
$taxon->uuid
|
38 |
|
|
)
|
39 |
|
|
)
|
40 |
|
|
);
|
41 |
bdd382be
|
Andreas Kohlbecker
|
$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 |
9aff46e4
|
Andreas Kohlbecker
|
}
|
52 |
bdd382be
|
Andreas Kohlbecker
|
if ($numberOfChildren > 0) {
|
53 |
|
|
$block = feature_block('Number of Taxa');
|
54 |
c651d3b1
|
Andreas Kohlbecker
|
// FIXME use compose_feature_block_wrap_elements() in next line
|
55 |
f78fda81
|
Andreas Kohlbecker
|
$block->content = array(markup_to_render_array(
|
56 |
|
|
'<ul class="feature-block-elements"><li>'
|
57 |
|
|
. $numberOfChildren . " " . $subRank
|
58 |
|
|
. '</li></ul>')
|
59 |
|
|
);
|
60 |
bdd382be
|
Andreas Kohlbecker
|
array_unshift($block_list, $block);
|
61 |
|
|
cdm_toc_list_add_item('Number of Taxa', 'number-of-taxa', NULL, TRUE);
|
62 |
9aff46e4
|
Andreas Kohlbecker
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
return $block_list;
|
66 |
bdd382be
|
Andreas Kohlbecker
|
}
|
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 |
5189a8ec
|
Andreas Kohlbecker
|
|
95 |
7508605c
|
Andreas Kohlbecker
|
/*
|
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 |
5189a8ec
|
Andreas Kohlbecker
|
/**
|
112 |
|
|
* @} End of "addtogroup hooks".
|
113 |
f6147a2a
|
Andreas Kohlbecker
|
*/
|