Browse Source

WIP stop trying to hook in to footnotes.module's theme functions.

ibidem
Alexander O'Neill 6 years ago
parent
commit
099f491acd
  1. 43
      bibcite_footnotes.module
  2. 25
      src/Plugin/Filter/ReferenceFootnotesFilter.php

43
bibcite_footnotes.module

@ -11,6 +11,27 @@ use Drupal\Core\Url;
use Drupal\Core\Link; use Drupal\Core\Link;
use Drupal\bibcite_footnotes\CitationTools; 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 /**_bibcite_foot
* Implements hook_help(). * Implements hook_help().
*/ */
@ -49,14 +70,6 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
'#wrapper_attributes' => ['class' => 'container'], '#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'; $references['#attached']['library'][] = 'bibcite_footnotes/reference_footnote';
$dont_show_backlink_text = $config->get('filters.filter_reference_footnotes.settings.reference_dont_show_backlink_text'); $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'); $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(); $link = Link::fromTextAndUrl($fn['value'], $url)->toRenderable();
$variables['fn']['fn'][] = $link; $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';
}

25
src/Plugin/Filter/ReferenceFootnotesFilter.php

@ -26,6 +26,8 @@ use Drupal\footnotes\Plugin\Filter\FootnotesFilter;
* ) * )
*/ */
class ReferenceFootnotesFilter extends FootnotesFilter { class ReferenceFootnotesFilter extends FootnotesFilter {
const ENDNOTE = 0;
const REFERENCE = 1;
/** /**
* Object with configuration for reference footnotes. * Object with configuration for reference footnotes.
@ -142,16 +144,15 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
if ($this->settings['footnotes_ibid']) { if ($this->settings['footnotes_ibid']) {
$this->ibidemify($store_matches); $this->ibidemify($store_matches);
} }
if (count($store_matches) > 0) { 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 // 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 // themed as a list
// 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
$markup = [ $markup = [
'#theme' => 'footnote_list', '#theme' => 'footnote_list',
'#footnotes' => $store_matches, '#footnotes' => $store_matches,
@ -258,6 +259,8 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
'#theme' => 'footnote_link', '#theme' => 'footnote_link',
'fn' => $fn, 'fn' => $fn,
]; ];
$result = \Drupal::service('renderer')->render($fn, FALSE); $result = \Drupal::service('renderer')->render($fn, FALSE);
return $result; return $result;
@ -333,4 +336,10 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
} }
ksm($footnotes); ksm($footnotes);
} }
protected function extractNotesByType($type, $footnotes) {
foreach ($footnotes as $fn) {
}
}
} }

Loading…
Cancel
Save