From d5fef241bada76eb7eead4d283d33ab9e9cd2d98 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Wed, 3 Apr 2019 00:43:31 -0300 Subject: [PATCH] Stpo using separate notes sections. Works Cited can be rendered from teh field. --- bibcite_footnotes.module | 19 ++++++++----------- .../Filter/ReferenceFootnotesFilter.php | 13 +------------ 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index b9585c5..c0b1a07 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -69,7 +69,7 @@ function bibcite_footnotes_preprocess_bibcite_footnote_list(&$variables) { $notes = [ '#theme' => 'item_list', '#list_type' => 'ul', - '#title' => $variables['note_type'] == ReferenceFootnotesFilter::ENDNOTE ? $config['notes_section_label'] : $config['references_section_label'], + '#title' => $variables['note_type'] == $config['notes_section_label'], '#attributes' => ['class' => 'footnotes'], '#wrapper_attributes' => ['class' => 'container'], ]; @@ -91,7 +91,7 @@ function bibcite_footnotes_preprocess_bibcite_footnote_list(&$variables) { $build = []; $reference_entity_id = $fn['reference']; - $footnote_link_text = ($dont_show_backlink_text && $reference_entity_id) ? '^' : $fn['value']; + $footnote_link_text = ($dont_show_backlink_text) ? '^' : $fn['value']; if (!is_array($fn['ref_id'])) { $url = Url::fromUserInput('#' . $fn['ref_id'], ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-link']]); $link = Link::fromTextAndUrl(($footnote_link_text), $url)->toRenderable(); @@ -126,8 +126,8 @@ function bibcite_footnotes_preprocess_bibcite_footnote_list(&$variables) { . '', ]; } - else if (!empty($fn['text']) && $variables['note_type'] == ReferenceFootnotesFilter::ENDNOTE) { - $build['footnote-link'] = Link::fromTextAndUrl($fn['value'], $url)->toRenderable(); + else if (!empty($fn['text'])) { + $build['footnote-link'] = Link::fromTextAndUrl($footnote_link_text, $url)->toRenderable(); $build['footnote-text'] = [ '#type' => 'markup', '#markup' => ' ' . $fn['text'] . '', @@ -194,7 +194,8 @@ function bibcite_footnotes_preprocess_bibcite_footnote_link(&$variables) { $citation_data = $citation_tools->getRenderableReference($citation_entity_id); // Citation contains a page reference, so construct parenthetical footnote. - if (!empty($fn['page'])) { + // @TODO: Make it explicit. + if (!empty($fn['page'] && !is_numeric($fn['value']))) { $fn['value'] = "({$fn['value']}, {$fn['page']})"; $citation_data['#data']['page'] = $fn['page']; $class .= '-inline'; @@ -202,13 +203,9 @@ function bibcite_footnotes_preprocess_bibcite_footnote_link(&$variables) { $title = trim(strip_tags(render($citation_data))); $url = Url::fromUserInput('#' . $fn['fn_id'], ['attributes' => ['id' => $fn['ref_id'], 'class' => $class, 'title' => $title]]); + -// We need to delete the cached markup to render it in a different mode. - unset($citation_data['#markup']); - unset($citation_data['#children']); - - $citation_data['#data']['mode'] = 'citation'; - $link = Link::fromTextAndUrl(render($citation_data), $url)->toRenderable(); + $link = Link::fromTextAndUrl($fn['value'], $url)->toRenderable(); unset($variables['fn']['fn']); $variables['fn']['fn'] = $link; // $variables['fn']['fn'][] = $link; diff --git a/src/Plugin/Filter/ReferenceFootnotesFilter.php b/src/Plugin/Filter/ReferenceFootnotesFilter.php index 47f1890..e803055 100644 --- a/src/Plugin/Filter/ReferenceFootnotesFilter.php +++ b/src/Plugin/Filter/ReferenceFootnotesFilter.php @@ -145,8 +145,6 @@ class ReferenceFootnotesFilter extends FootnotesFilter { if (count($store_matches) > 0) { // Separate out endontes and reference notes. - $notes = $this->extractNotesByType(self::ENDNOTE, $store_matches); - $references = $this->extractNotesByType(self::REFERENCE, $store_matches); if ($this->settings['footnotes_ibid']) { $this->ibidemify($references); @@ -155,19 +153,10 @@ class ReferenceFootnotesFilter extends FootnotesFilter { // themed as a list $markup = [ '#theme' => 'bibcite_footnote_list', - '#notes' => $notes, - '#note_type' => self::ENDNOTE, + '#notes' => $store_matches, '#config' => $this->settings, ]; $str = \Drupal::service('renderer')->render($markup, FALSE); - - $markup = [ - '#theme' => 'bibcite_footnote_list', - '#notes' => $references, - '#note_type' => self::REFERENCE, - '#config' => $this->settings, - ]; - $str .= \Drupal::service('renderer')->render($markup, FALSE); } // Reset the static variables so they can be used again next time. $n = 0;