Project

General

Profile

Download (3.54 KB) Statistics
| Branch: | Tag: | Revision:
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
        [
37
          get_current_classification_uuid(),
38
          $taxon->uuid,
39
        ]
40
      )
41
    );
42
    $subRank = 'sub taxa';
43
    if ($taxon->name->rank->titleCache == "Genus") {
44
      $subRank = "species";
45
    }
46
    else {
47
      if ($taxon->name->rank->titleCache == "Species") {
48
        if ($numberOfChildren == 1) {
49
          $subRank = "infraspecific taxon";
50
        }
51
        else {
52
          $subRank = "infraspecific taxa";
53
        }
54
      }
55
    }
56
    if ($numberOfChildren > 0) {
57

    
58
      $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
59
      $feature_num_of_taxa = make_pseudo_feature('Number of Taxa', PSEUDO_FEATURE_NUMBER_OF_TAXA);
60
      $block = feature_block(t('Number of Taxa'), $feature_num_of_taxa);
61
      $block->content[] = compose_feature_block_wrap_elements([
62
        markup_to_render_array(
63
          '<ul class="feature-block-elements"><li>'
64
          . $numberOfChildren . " " . $subRank
65
          . '</li></ul>')]
66
        , $feature_num_of_taxa);
67
      $block_list[$pseudo_feature_weights[PSEUDO_FEATURE_NUMBER_OF_TAXA]] = $block;
68
      cdm_toc_list_add_item('Number of Taxa', 'number-of-taxa', NULL, TRUE);
69
    }
70
  }
71

    
72
  return $block_list;
73
}
74

    
75
/**
76
 * Alter the content of a feature block.
77
 *
78
 * Modules implementing this hook can add, remove or modify
79
 * feature blocks contents of the taxon general page part and of the
80
 * specimen page part.
81
 *
82
 * @param array $block_content
83
 *   Drupal render array for the content of the feature block
84
 * @param object $feature
85
 *   The feature this block belongs to
86
 * @param object $elements
87
 *   An array of CDM DescriptionElement instances which are being displayed in
88
 *   this block. Even if this array is passed as reference it should not being
89
 *   altered. Passing by reference is only recommended to reduce the memory
90
 *   footprint.
91
 */
92
function hook_cdm_feature_node_block_content_alter(&$block_content, $feature, &$elements){
93
    if($feature->uuid == UUID_DISTRIBUTION){
94
        $block_content['my_custom_render_element'] = array(
95
            '#type' => 'markup',
96
            '#markup' => '<h1>Hello World</h1>',
97
            '#weight' => 99, // Show at the bottom of the block
98
        );
99
    }
100
}
101

    
102
/*
103
 * Alter the merged feature tree for a taxon profile page.
104
 *
105
 * @param $merged_tree
106
 *   The $merged_tree as produced by merged_taxon_feature_tree($taxon)
107
 * @param $taxon
108
 *   A CDM Taxon instance
109
 */
110
function hook_merged_taxon_feature_tree_alter($taxon, &$merged_tree){
111

    
112
  // find the distribution feature node
113
  $distribution_node =& cdm_feature_tree_find_node($merged_tree->root->childNodes, UUID_DISTRIBUTION);
114
  // remove all TextData
115
  $distribution_node->descriptionElements['TextData'] = array();
116
}
117

    
118
/**
119
 * @} End of "addtogroup hooks".
120
 */
(5-5/18)