Project

General

Profile

« Previous | Next » 

Revision 9f9fe101

Added by Andreas Kohlbecker over 3 years ago

ref #8543 refactoring: renaming variables & moving functions to other files

View differences:

modules/cdm_dataportal/includes/common.inc
890 890
function icon_link($path, $fragment = '') {
891 891
  $iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', ['class' => ['superscript']]), $path, ['html' => TRUE, 'fragment' => $fragment] );
892 892
  return $iconlink;
893
}
893
}
894

  
895

  
896
/**
897
 * @param $entity
898
 * @param $config array
899
 *   An associative array to configure the display of the annotations and
900
 *   sources. The array has the following keys
901
 *   - sources_as_content
902
 *   - link_to_name_used_in_source
903
 *   - link_to_reference
904
 *   - add_footnote_keys
905
 *   - bibliography_aware
906
 *   Valid values are 1 or 0.
907
 * @param $inline_text_prefix
908
 *   Only used to decide if the source references should be enclosed in
909
 *   brackets or not when displayed inline. This text will not be included into
910
 *   the response.
911
 * @param $footnote_list_key_suggestion string
912
 *    optional parameter. If this paramter is left empty (null, 0, "") the
913
 *   footnote key will be determined by the nested method calls by calling
914
 *   RenderHints::getFootnoteListKey(). NOTE: the footnore key for annotations
915
 *   will be set to RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS.
916
 * @return array
917
 * an associative array with the following elements:
918
 *   - foot_note_keys: all footnote keys as markup
919
 *   - source_references: an array of the source references citations
920
 *   - names used in source: an associative array of the names in source,
921
 *        the name in source strings are de-duplicated
922
 *        !!!NOTE!!!!: this field will most probably be removed soon (TODO)
923
 *
924
 */
925
function handle_annotations_and_sources($entity, $config, $inline_text_prefix, $footnote_list_key_suggestion) {
926

  
927
  $annotations_and_sources = array(
928
    'foot_note_keys' => NULL,
929
    'source_references' => [],
930
    'names_used_in_source' => []
931
  );
932

  
933
  // some entity types only have single sources:
934
  $sources = cdm_entity_sources_sorted($entity);
935

  
936
  if ($config['sources_as_content'] == 1) {
937
    foreach ($sources as $source) {
938
      if (_is_original_source_type($source)) {
939
        $reference_citation = render_original_source(
940
          $source,
941
          $config['link_to_reference'] == 1,
942
          $config['link_to_name_used_in_source'] == 1
943
        );
944

  
945
        if ($reference_citation) {
946
          if (empty($inline_text_prefix)) {
947
            $annotations_and_sources['source_references'][] = $reference_citation;
948
          } else {
949
            $annotations_and_sources['source_references'][] = ' (' . $reference_citation . ')';
950
          }
951
        }
952

  
953
        // also put the name in source into the array, these are already included in the $reference_citation but are
954
        // still required to be available separately in some contexts.
955
        $name_in_source_render_array = compose_name_in_source(
956
          $source,
957
          $config['link_to_name_used_in_source'] == 1
958
        );
959

  
960
        if (!empty($name_in_source_render_array)) {
961
          $annotations_and_sources['names_used_in_source'][$name_in_source_render_array['#_plaintext']] = drupal_render($name_in_source_render_array);
962
        }
963
      }
964
    } // END of loop over sources
965

  
966
    // annotations footnotes separate from sources
967
    $annotations_and_sources['foot_note_keys'] = render_footnote_keys(
968
      cdm_entity_annotations_as_footnote_keys($entity, $footnote_list_key_suggestion), ', '
969
    );
970

  
971
  } // END of references inline
972

  
973
  // footnotes for sources and annotations or put into into bibliography if requested ...
974
  if ($config['add_footnote_keys'] == 1) {
975
    $annotations_and_sources['foot_note_keys'] = render_entity_footnotes(
976
      $entity, ',',
977
      $footnote_list_key_suggestion,
978
      $config['link_to_reference'] == 1,
979
      $config['link_to_name_used_in_source'] == 1,
980
      !empty($config['bibliography_aware'])
981
    );
982
  }
983

  
984
  return $annotations_and_sources;
985
}
986

  
987
/**
988
 * Get the source or the sources from a cdm entity and return them ordered by see compare_original_sources()
989
 * (Some entity types only have single sources)
990
 * @param $entity
991
 *
992
 * @return array
993
 */
994
function cdm_entity_sources_sorted($entity) {
995
  if (isset($entity->source) && is_object($entity->source)) {
996
    $sources = [$entity->source];
997
  }
998
  else if (isset($entity->sources)) {
999
    $sources = $entity->sources;
1000
  }
1001
  else {
1002
    $sources = [];
1003
  }
1004
  usort($sources, 'compare_original_sources');
1005
  return $sources;
1006
}

Also available in: Unified diff