From 099f491acd7c1c96bdd6adf3379b1afebf7b03b3 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 2 Nov 2018 08:11:27 -0300 Subject: [PATCH] WIP stop trying to hook in to footnotes.module's theme functions. --- bibcite_footnotes.module | 43 +++++++++---------- .../Filter/ReferenceFootnotesFilter.php | 25 +++++++---- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index 39c617e..754f094 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -11,6 +11,27 @@ use Drupal\Core\Url; use Drupal\Core\Link; use Drupal\bibcite_footnotes\CitationTools; +/** + * Implements hook_theme(). + */ +function bibcite_footnotes_theme() { + return [ + 'bibcite_footnote_link' => [ + 'render element' => 'fn', + 'template' => 'footnote-link', + ], + 'bibcite_footnote_list' => [ + 'render element' => 'footnotes', + 'path' => drupal_get_path('module', 'bibcite_footnotes') . '/templates', + 'template' => 'footnote-list', + 'variables' => [ + 'notes' => [], + 'note_type' => [], + ], + ], + ]; +} + /**_bibcite_foot * Implements hook_help(). */ @@ -49,14 +70,6 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) { '#wrapper_attributes' => ['class' => 'container'], ]; - $references= [ - '#theme' => 'item_list', - '#list_type' => 'ul', - '#title' => $config->get('filters.filter_reference_footnotes.settings.references_section_label'), - '#attributes' => ['class' => 'footnotes'], - '#wrapper_attributes' => ['class' => 'container'], - - ]; $references['#attached']['library'][] = 'bibcite_footnotes/reference_footnote'; $dont_show_backlink_text = $config->get('filters.filter_reference_footnotes.settings.reference_dont_show_backlink_text'); $sort_references_by = $config->get('filters.filter_reference_footnotes.settings.reference_sort_by'); @@ -169,17 +182,3 @@ function bibcite_footnotes_preprocess_footnote_link(&$variables) { $link = Link::fromTextAndUrl($fn['value'], $url)->toRenderable(); $variables['fn']['fn'][] = $link; } - -function bibcite_footnotes_theme_registry_alter(&$theme_registry) { - unset($theme_registry['footnote_list']['function']); - $theme_registry['footnote_list']['path'] = drupal_get_path('module', 'bibcite_footnotes') . '/templates'; - $theme_registry['footnote_list']['template'] = 'footnote-list'; - $theme_registry['footnote_list']['variables']['notes'] = []; - $theme_registry['footnote_list']['variables']['references'] = []; - $theme_registry['footnote_list']['variables']['footnotes'] = []; - - unset($theme_registry['footnote_link']['function']); - $theme_registry['footnote_link']['path'] = drupal_get_path('module', 'bibcite_footnotes') . '/templates'; - $theme_registry['footnote_link']['template'] = 'footnote-link'; -} - diff --git a/src/Plugin/Filter/ReferenceFootnotesFilter.php b/src/Plugin/Filter/ReferenceFootnotesFilter.php index fcddbf7..faeacda 100644 --- a/src/Plugin/Filter/ReferenceFootnotesFilter.php +++ b/src/Plugin/Filter/ReferenceFootnotesFilter.php @@ -26,6 +26,8 @@ use Drupal\footnotes\Plugin\Filter\FootnotesFilter; * ) */ class ReferenceFootnotesFilter extends FootnotesFilter { + const ENDNOTE = 0; + const REFERENCE = 1; /** * Object with configuration for reference footnotes. @@ -142,16 +144,15 @@ class ReferenceFootnotesFilter extends FootnotesFilter { if ($this->settings['footnotes_ibid']) { $this->ibidemify($store_matches); } + if (count($store_matches) > 0) { + // Separate out endontes and reference notes. + $notes = $this->extractNotesByType(self::NOTES, $store_matches); + $references = $this->extractNotesByType(self::REFERENCES, $store_matches); + + // Only if there are stored fn matches, pass the array of fns to be - // themed as a list Drupal 7 requires we use "render element" which - // just introduces a wrapper around the old array. - // @FIXME - // theme() has been renamed to _theme() and should NEVER be called - // directly. Calling _theme() directly can alter the expected output and - // potentially introduce security issues - // (see https://www.drupal.org/node/2195739). You should use renderable - // arrays instead. @see https://www.drupal.org/node/2195739 + // themed as a list $markup = [ '#theme' => 'footnote_list', '#footnotes' => $store_matches, @@ -258,6 +259,8 @@ class ReferenceFootnotesFilter extends FootnotesFilter { '#theme' => 'footnote_link', 'fn' => $fn, ]; + + $result = \Drupal::service('renderer')->render($fn, FALSE); return $result; @@ -333,4 +336,10 @@ class ReferenceFootnotesFilter extends FootnotesFilter { } ksm($footnotes); } + + protected function extractNotesByType($type, $footnotes) { + foreach ($footnotes as $fn) { + + } + } }