@ -10,8 +10,31 @@ use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Drupal\Core\Link;
use Drupal\bibcite_footnotes\CitationTools;
use Drupal\bibcite_footnotes\CitationTools;
use Drupal\bibcite_footnotes\Plugin\Filter\ReferenceFootnotesFilter;
/**_bibcite_foot
/**
* Implements hook_theme().
*/
function bibcite_footnotes_theme() {
return [
'bibcite_footnote_link' => [
'render element' => 'fn',
'template' => 'bibcite-footnote-link',
],
'bibcite_footnote_list' => [
'render element' => 'footnotes',
'path' => drupal_get_path('module', 'bibcite_footnotes') . '/templates',
'template' => 'bibcite-footnote-list',
'variables' => [
'notes' => [],
'note_type' => [],
'config' => [],
],
],
];
}
/**
* Implements hook_help().
* Implements hook_help().
*/
*/
function bibcite_footnotes_help($route_name, RouteMatchInterface $route_match) {
function bibcite_footnotes_help($route_name, RouteMatchInterface $route_match) {
@ -28,7 +51,7 @@ function bibcite_footnotes_help($route_name, RouteMatchInterface $route_match) {
}
}
/**
/**
* Implementation of hook_preprocess_footnote_list().
* Implementation of hook_preprocess_bibcite_ footnote_list().
*
*
* Gatehrs all notes and prints out Notes and References as separate lists.
* Gatehrs all notes and prints out Notes and References as separate lists.
*
*
@ -37,29 +60,21 @@ function bibcite_footnotes_help($route_name, RouteMatchInterface $route_match) {
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
*/
function bibcite_footnotes_preprocess_footnote_list(&$variables) {
function bibcite_footnotes_preprocess_bibcite_ footnote_list(&$variables) {
$config = \Drupal::config('filter.format.rich_text_references');//filters.filter_reference_footnotes.settings') ;
$config = $variables['config'] ;
$footnotes = $variables['foot notes'];
$footnotes = $variables['notes'];
$notes = [
$notes = [
'#theme' => 'item_list',
'#theme' => 'item_list',
'#list_type' => 'ul',
'#list_type' => 'ul',
'#title' => $config->get('filters.filter_reference_footnotes.settings.notes_section_label') ,
'#title' => $variables['note_type'] == ReferenceFootnotesFilter::ENDNOTE ? $config['notes_section_label'] : $config['references_section_label'] ,
'#attributes' => ['class' => 'footnotes'],
'#attributes' => ['class' => 'footnotes'],
'#wrapper_attributes' => ['class' => 'container'],
'#wrapper_attributes' => ['class' => 'container'],
];
];
$references= [
$notes['#attached']['library'][] = 'bibcite_footnotes/reference_footnote';
'#theme' => 'item_list',
$dont_show_backlink_text = $config['reference_dont_show_backlink_text'];
'#list_type' => 'ul',
$sort_references_by = $config['reference_sort_by'];
'#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');
$citation_tools = new CitationTools();
$citation_tools = new CitationTools();
foreach ($footnotes as $fn) {
foreach ($footnotes as $fn) {
$item = [
$item = [
@ -97,53 +112,66 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
$override_page_in_citation = FALSE;
$override_page_in_citation = FALSE;
}
}
if (!empty($fn['text'])) {
if ($fn['ibid']) {
// Handle the case where an endnote contains text and a reference.
$build['#type'] = 'markup';
// It will appear in both lists. But the link text for the endnote should
$build['#markup'] = ' <span class="endnote-text"><span class="ibid">'
// always be the title of the note. So make a copy of the biuld arrray
. t('Ibid') . '.</span>'
// and change the link text.
. (!empty($fn['page']) ? ', ' . $fn['page'] : '')
$note_build = $build + ['#type' => 'markup', '#markup' => ' <span class="endnote-text">' . $fn['text'] . '</span>'];
. '</span>';
$note_build['footnote-link'] = Link::fromTextAndUrl($fn['value'], $url)->toRenderable();
}
if (!empty($reference_entity_id)) {
else if (!empty($fn['text']) && $variables['note_type'] == ReferenceFootnotesFilter::ENDNOTE) {
$citation_build = $citation_tools->getRenderableReference($reference_entity_id);
$build['#type'] = 'markup';
$note_build[] = $citation_build;
$build['#markup'] = ' <span class="endnote-text">' . $fn['text'] . '</span>';
}
$build['footnote-link'] = Link::fromTextAndUrl($fn['value'], $url)->toRenderable();
$note_item = [] + $item;
$note_item['#markup'] = render($note_build);
$notes['#items'][] = $note_item;
}
}
if (!empty($reference_entity_id)) {
if (!empty($reference_entity_id)) {
$citation_build = $citation_tools->getRenderableReference($reference_entity_id);
if (!$fn['ibid']) {
if ($override_page_in_citation) {
$citation_build = $citation_tools->getRenderableReference($reference_entity_id);
$citation_build['#data']['page'] = $override_page_in_citation;
if ($override_page_in_citation) {
$citation_build['#data']['page'] = $override_page_in_citation;
}
$build[] = $citation_build;
}
}
$build[] = $citation_build;
$render = render($build);
$render = render($build);
$item['#markup'] = $render;
$item['sort'] = trim(strip_tags(render($citation_build)));
$item['sort'] = trim(strip_tags(render($citation_build)));
$references['#items'][] = $item;
}
}
$item['#markup'] = $render;
$notes['#items'][] = $item;
$reference_entity_id = FALSE;
$render = FALSE;
}
}
$variables['notes'] = $notes;
if ($sort_references_by == 'alphabetical' && $variables['note_type'] == ReferenceFootnotesFilter::REFERENCE) {
usort($notes['#items'], '_bibcite_footnotes_reference_array_cmp');
if ($sort_references_by == 'alphabetical') {
usort($references['#items'], '_bibcite_footnotes_reference_array_cmp');
}
}
$variables['references'] = $referenc es;
$variables['notes'] = $notes;
}
}
/**
* Comparator function for sorting lists of references.
*
* @param $a First item to compare
* @param $b Second item to compare
* @return int Result of the comparison.
*/
function _bibcite_footnotes_reference_array_cmp($a, $b) {
function _bibcite_footnotes_reference_array_cmp($a, $b) {
$a1 = (!empty($a['sort']) ? strtolower($a['sort']) : '');
$a1 = (!empty($a['sort']) ? strtolower($a['sort']) : '');
$b1 = (!empty($b['sort']) ? strtolower($b['sort']) : '');
$b1 = (!empty($b['sort']) ? strtolower($b['sort']) : '');
return strcmp($a1, $b1);
return strcmp($a1, $b1);
}
}
function bibcite_footnotes_preprocess_footnote_link(&$variables) {
/**
* Implementation of hook_preprocess_bibcite_footnote_link().
*
* Construct a link inside a block of text so that it points to the reference list.
*
* @param $variables
*/
function bibcite_footnotes_preprocess_bibcite_footnote_link(&$variables) {
// $variables['fn']['fn']['#type'] = 'markeup';
// $variables['fn']['fn']['#type'] = 'markeup';
// $variables['fn']['fn']['#markup'] = '<h2>Hello!</h2>';
// $variables['fn']['fn']['#markup'] = '<h2>Hello!</h2>';
$fn = $variables['fn']['fn'];
$fn = $variables['fn']['fn'];
@ -169,17 +197,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';
}