From b10cce0daeaf71fae026b3d6953699c3782bd4f2 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Tue, 30 Oct 2018 05:27:31 -0300 Subject: [PATCH] Add option to sort References alphabetically. --- bibcite_footnotes.module | 70 +++---------------- .../Filter/ReferenceFootnotesFilter.php | 4 +- 2 files changed, 13 insertions(+), 61 deletions(-) diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index 60a6837..8aed8a1 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -104,9 +104,11 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) { ->getStorage('bibcite_reference') ->load($reference_entity_id); $data = $serializer->normalize($reference_storage, 'csl'); - $build[] = ['#theme' => 'bibcite_citation', '#data' => $data]; + $citation_build = ['#theme' => 'bibcite_citation', '#data' => $data]; + $build[] = $citation_build; $render = render($build); $item['#markup'] = $render; + $item['sort'] = trim(strip_tags(render($citation_build))); $references['#items'][] = $item; } @@ -121,8 +123,16 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) { $variables['notes'] = $notes; + if ($sort_references_by == 'alphabetical') { + usort($references['#items'], '_bibcite_footnotes_reference_array_cmp'); + } $variables['references'] = $references; +} +function _bibcite_footnotes_reference_array_cmp($a, $b) { + $a1 = (!empty($a['sort']) ? strtolower($a['sort']) : ''); + $b1 = (!empty($b['sort']) ? strtolower($b['sort']) : ''); + return strcmp($a1, $b1); } /** @@ -146,61 +156,3 @@ function bibcite_footnotes_theme_registry_alter(&$theme_registry) { $theme_registry['footnote_list']['variables']['footnotes'] = []; } -function bibcite_footnotes_theme_footnote_list($footnotes) { - // @todo: change this ugly array for arguments in the function. - $footnotes = $footnotes['footnotes']['#footnotes']; - - $notes = [ - '#theme' => 'item_list', - '#list_type' => 'ul', - '#title' => 'Notes', - '#attributes' => ['class' => ''], - '#wrapper_attributes' => ['class' => 'container'], - ]; - -// return drupal_render($content); - $str = '