Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / taxon-node.inc @ 31bb0452

History | View | Annotate | Download (2.14 KB)

1
<?php
2

    
3
/**
4
 * @file
5
 * Taxon Node functions.
6
 *
7
 * @copyright
8
 *   (C) 2007-2020 EDIT
9
 *   European Distributed Institute of Taxonomy
10
 *   http://www.e-taxonomy.eu
11
 *
12
 *   The contents of this module are subject to the Mozilla
13
 *   Public License Version 1.1.
14
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
15
 *
16
 * @author
17
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
18
 */
19

    
20
/**
21
 * Created a render array with taxon node information like states.
22
 *
23
 * @param array $taxon_nodes
24
 *
25
 * @gropup compose
26
 */
27
function compose_taxon_node_status(array $taxon_nodes){
28

    
29
  $render_array = [];
30
  if($taxon_nodes && count($taxon_nodes) > 0){
31
    $label_plural = false;
32
    $state_markup_tokens = [];
33
    foreach ($taxon_nodes as $taxon_node){
34
      if(isset($taxon_node->status)){
35
        $state_label = strtolower($taxon_node->status);
36
        $classification_markup = ' <span class="' . html_class_attribute_ref($taxon_node->classification) .'">[' . $taxon_node->classification->titleCache . ']</span>';
37
        $state_markup = '<span class="' . html_class_attribute_ref($taxon_node) .'">' . $state_label . '%s</span>'; // %s will be replaced by the $classification_markup or by ''
38
        $state_markup_tokens[] = [
39
          'states' => $state_markup,
40
          'classification' => $classification_markup,
41
          'closing_tag' => '</span>'
42
        ];
43
      }
44
    }
45
    if(count($state_markup_tokens) > 0){
46
      $state_markup = [];
47
      $label_plural |= count($state_markup_tokens) > 1;
48
      $label = $label_plural ? t('Placement status') : t('Placement status');
49
      if(count($state_markup_tokens) > 1){
50
        foreach ($state_markup_tokens as $tokes){
51
          $state_markup[] = sprintf($tokes['states'], $tokes['classification']);
52
        }
53
      } else {
54
        foreach ($state_markup_tokens as $tokes){
55
          $state_markup[] = sprintf($tokes['states'], '');
56
        }
57
      }
58
      $render_array['taxon-node-status'] = markup_to_render_array($label . ': ' . join('; ', $state_markup));
59
      $render_array['taxon-node-status']['#prefix'] = '<div class="taxon-node-status">';
60
      $render_array['taxon-node-status']['#suffix'] = '</div>';
61
    }
62
  }
63
  return $render_array;
64
}
Add picture from clipboard (Maximum size: 40 MB)