Project

General

Profile

Revision 4feeabc7

ID4feeabc7eb75a09ab5a445413a4b6a3505c49e37
Parent 4b3be949
Child ed0183ea

Added by Andreas Kohlbecker over 3 years ago

fix #4490 taxon page tab labels configurable and fixing translation issue with menu items

View differences:

modules/cdm_dataportal/cdm_dataportal.module
529 529
  // --- tabbed taxon page
530 530
  if (variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
531 531
    $items['cdm_dataportal/taxon/%'] = array(
532
      'title' => '@tabname',
533
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'General'))),
532
      'title' => cdm_taxonpage_tab_label('General'),
534 533
      'page callback' => 'cdm_dataportal_taxon_page_view',
535 534
      'access arguments' => array('access cdm content'),
536 535
      'type' => MENU_CALLBACK,
......
540 539
    );
541 540

  
542 541
    $items['cdm_dataportal/taxon/%/all'] = array(
543
      'title' => '@tabname',
544
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'General'))),
542
      'title' => cdm_taxonpage_tab_label('General'),
545 543
      'page callback' => 'cdm_dataportal_taxon_page_view',
546 544
      'access arguments' => array('access cdm content'),
547 545
      'type' => MENU_CALLBACK,
......
551 549
    );
552 550

  
553 551
    $items['cdm_dataportal/taxon/%/description'] = array(
554
      'title' => '@tabname',
555
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'General'))),
552
      'title' => cdm_taxonpage_tab_label('General'),
556 553
      'page callback' => 'cdm_dataportal_taxon_page_view',
557 554
      'access arguments' => array('access cdm content'),
558 555
      'type' => MENU_DEFAULT_LOCAL_TASK,
......
562 559
    );
563 560

  
564 561
    $items['cdm_dataportal/taxon/%/synonymy'] = array(
565
      'title' => '@tabname',
566
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'Synonymy'))),
562
      'title' => cdm_taxonpage_tab_label('Synonymy'),
567 563
      'page callback' => 'cdm_dataportal_taxon_page_view',
568 564
      'access arguments' => array('access cdm content'),
569 565
      'type' => MENU_LOCAL_TASK,
......
572 568
      , // Expected callback arguments: taxon_uuid and ...
573 569
    );
574 570
    $items['cdm_dataportal/taxon/%/images'] = array( // Images
575
      'title' => '@tabname',
576
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'Images'))),
571
      'title' => cdm_taxonpage_tab_label('Images'),
577 572
      'page callback' => 'cdm_dataportal_taxon_page_view',
578 573
      'access arguments' => array('access cdm content'),
579 574
      'type' => MENU_LOCAL_TASK,
......
583 578
    );
584 579

  
585 580
    $items['cdm_dataportal/taxon/%/specimens'] = array( // Specimens
586
      'title' => '@tabname',
587
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'Specimens'))),
581
      'title' => cdm_taxonpage_tab_label('Specimens'),
588 582
      'page callback' => 'cdm_dataportal_taxon_page_view',
589 583
      'access arguments' => array('access cdm content'),
590 584
      'type' => MENU_LOCAL_TASK,
......
594 588
    );
595 589

  
596 590
    $items['cdm_dataportal/taxon/%/keys'] = array( // Keys
597
      'title' => '@tabname',
598
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'Keys'))),
591
      'title' => cdm_taxonpage_tab_label('Keys'),
599 592
      'page callback' => 'cdm_dataportal_taxon_page_view',
600 593
      'access arguments' => array('access cdm content'),
601 594
      'type' => MENU_LOCAL_TASK,
......
605 598
    );
606 599

  
607 600
    $items['cdm_dataportal/taxon/%/experts'] = array( // Experts
608
      'title' => '@tabname',
609
      'title arguments' => array('@tabname' => theme('cdm_taxonpage_tab', array('tabname' => 'Experts'))),
601
      'title' => cdm_taxonpage_tab_label('Experts'),
610 602
        'page callback' => 'cdm_dataportal_taxon_page_view',
611 603
        'access arguments' => array('access cdm content'),
612 604
        'type' => MENU_LOCAL_TASK,
modules/cdm_dataportal/includes/pages.inc
492 492
  if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
493 493
    $images_html = '<div id="images" class="page-part">';
494 494
    if ($page_part == 'all') {
495
      $images_html .= '<h2>' . t('Images') . '</h2>';
495
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
496 496
    }
497 497
    // Get the image gallery as configured by the admin.
498 498
    $default_image_gallery = 'default';
499 499
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
500
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
500 501
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
501 502
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
502 503
      // flash we also need to provide an the default gallery as alternative
......
524 525
  if (($page_part == 'synonymy' || $page_part == 'all')) {
525 526
    $synonymy_html = '<div id="synonymy" class="page-part">';
526 527
    if ($page_part == 'all') {
527
      $synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
528
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
528 529
    }
529 530
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
530 531

  
......
538 539
  // --- PAGE PART: SPECIMENS --- //
539 540
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
540 541
    $render_array['specimens'] = array(
541
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
542
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
542 543
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
543 544
        '#suffix' => '</div>',
544 545
    );
......
551 552
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
552 553
    $keys_html = '<div id="keys" class="page-part">';
553 554
    if ($page_part == 'all') {
554
      $keys_html .= '<h2>' . t('Keys') . '</h2>';
555
      $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
555 556
    }
556 557
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
557 558
    $keys_html .= '</div>';
......
562 563

  
563 564
  if (array_search('experts', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'experts' || $page_part == 'all')) {
564 565
    $render_array['experts'] = array(
565
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t('Experts') . '</h2>' : ''),
566
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
566 567
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
567 568
        '#suffix' => '</div>',
568 569
    );
......
571 572
  // ------------------ END OF PARTS -------------- //
572 573

  
573 574
  // adjust weights of page and toc elements according to the settings
574
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
575
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
575 576
  foreach($taxontabs_weights as $tab_key => $weight){
576 577
    if(isset($render_array[$tab_key])){
577 578
      $render_array[$tab_key]['#weight'] = $weight;
......
588 589
        if($tab_key != 'general'){
589 590
          // add entry for page part
590 591
          $toc_elements[] = array(
591
              'data' => l(t('@tab-name', array('@tab-name' => ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
592
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
592 593
              'class' => array('page-part-toc-item-' . $tab_key)
593 594
          );
594 595
        } else {
......
1117 1118
  RenderHints::popFromRenderStack();
1118 1119
  return $render_array;
1119 1120
}
1121

  
1122
/**
1123
 * Provides the the label string for taxon page tabs.
1124
 *
1125
 * The $tabname as passed to the method will be returned if no override
1126
 * label is configured in the settings.
1127
 */
1128
function cdm_taxonpage_tab_label($tabname) {
1129
  static $taxon_tabs_labels = null;
1130
  if($taxon_tabs_labels == null){
1131
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1132
  }
1133
  $tabname_key = strtolower($tabname);
1134
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1135
    return $taxon_tabs_labels[$tabname_key];
1136
  }
1137
  return $tabname;
1138
}
modules/cdm_dataportal/settings.php
128 128
  );
129 129
}
130 130

  
131
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
131 132
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
132 133
  array(
133 134
    'general' => '-3',
......
139 140
    )
140 141
));
141 142

  
143

  
144
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
145
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
146
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
147
  array(
148
    'general' => null,
149
    'synonymy' => null,
150
    'images' => null,
151
    'specimens' => null,
152
    'keys' => null,
153
    'experts' => null,
154
  )
155
));
156

  
142 157
$taxon_tab_options = get_taxon_tabs_list();
143 158
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
144 159

  
......
1820 1835
  );
1821 1836

  
1822 1837
  // WEIGHT
1823
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1824
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1825
      '#tree' => true
1838
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1839
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1840
    '#title'  => 'Tabs order',
1841
    '#tree' => true,
1842
    '#description' => 'The weight value defines the order of the tabs or of the respective content block on the 
1843
        taxon page when it is the tabless mode.'
1826 1844
  );
1827 1845
  // Weights range from -delta to +delta, so delta should be at least half
1828 1846
  // of the amount of tabs present.
1829 1847
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1830 1848
  foreach (get_taxon_tabs_list() as $label) {
1831 1849
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1832
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1850
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1833 1851
        '#title' => $label,
1834 1852
        '#type'  => 'weight',
1835
        '#default_value' => $taxontabs_weights[$key],
1853
        '#default_value' => $taxon_tabs_weights[$key],
1836 1854
        '#delta' => $tab_weight_delta
1837 1855
    );
1838 1856
  }
1839 1857

  
1858
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1859
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1860
    '#title'  => 'Tab label override',
1861
    '#tree' => true,
1862
    '#description' => 'Setting a label for a tab will override the default label.'
1863
  );
1864
  foreach (get_taxon_tabs_list() as $label) {
1865
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1866
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1867
      '#title' => $label,
1868
      '#type'  => 'textfield',
1869
      '#default_value' => $taxon_tabs_labels[$key]
1870
    );
1871
  }
1872

  
1840 1873
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1841 1874
    '#type' => 'select',
1842 1875
    '#title' => t('Default tab to display') . ':',
modules/cdm_dataportal/theme/cdm_dataportal.page.theme
683 683
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
684 684
   */
685 685
  return '<div id="identificationKey">' . $out . '</div>';
686
}
687

  
688
/**
689
 * Returns HTML for taxon page tabs.
690
 *
691
 * Allows theming of the taxon page tabs.
692
 *
693
 * @param array $variables
694
 *   An associative array containing:
695
 *   - tabname
696
 *
697
 * @ingroup themeable
698
 */
699
function theme_cdm_taxonpage_tab($variables) {
700
  $tabname = $variables['tabname'];
701
  // TODO replace by using translations or theme the menue tabs itself instead?
702
  switch ($tabname) {
703
    default:
704
      return t('@tabname', array('@tabname' => $tabname));
705
  }
706
}
686
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)