' . t('About') . ''; $output .= '

' . t('Inline footnote links for BibCite References') . '

'; return $output; default: } } /** * Implementation of hook_preprocess_footnote_list(). * * Gatehrs all notes and prints out Notes and References as separate lists. * * @param $variables Theme variables. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ function bibcite_footnotes_preprocess_footnote_list(&$variables) { $config = \Drupal::config('filter.format.rich_text_references');//filters.filter_reference_footnotes.settings'); $footnotes = $variables['footnotes']; $notes = [ '#theme' => 'item_list', '#list_type' => 'ul', '#title' => $config->get('filters.filter_reference_footnotes.settings.notes_section_label'), '#attributes' => ['class' => 'footnotes'], '#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'); $serializer = \Drupal::service('serializer'); foreach ($footnotes as $fn) { $item = [ '#id' => $fn['fn_id'], '#wrapper_attributes' => [ 'class' => ['footnote'], ], ]; $build = []; preg_match('/\[bibcite_reference:(\d*)\]/', $fn['text'], $matches); $reference_entity_id = $matches[1]; if (!is_array($fn['ref_id'])) { // Output normal footnote. $url = Url::fromUserInput('#' . $fn['ref_id'], ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-link']]); $link = Link::fromTextAndUrl(($dont_show_backlink_text && $reference_entity_id ? '^' : $fn['value']), $url)->toRenderable(); $build[] = $link; } else { // Output footnote that has more than one reference to it in the body. // The only difference is to insert backlinks to all references. // Helper: we need to enumerate a, b, c... $abc = str_split("abcdefghijklmnopqrstuvwxyz"); $i = 0; $url = Url::fromUserInput('#' . $fn['ref_id'][0], ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-link']]); $build[] = Link::fromTextAndUrl($fn['value'], $url)->toRenderable(); foreach ($fn['ref_id'] as $ref) { $url = Url::fromUserInput( '#' . $ref, ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-multi']]); $build[] = Link::fromTextAndUrl($abc[$i], $url)->toRenderable(); $i++; } } if (!empty($reference_entity_id)) { $reference_storage = \Drupal::entityTypeManager() ->getStorage('bibcite_reference') ->load($reference_entity_id); $data = $serializer->normalize($reference_storage, 'csl'); $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; } else { $build[] = ['#type' => 'markup', '#markup' => ' ' . $fn['text']]; $render = render($build); $item['#markup'] = $render; $notes['#items'][] = $item; } } $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); } /** * Implements hook_theme(). */ function bibcite_footnotes_theme() { return [ 'bibcite_footnotes' => [ 'render element' => 'children', ], ]; } function bibcite_footnotes_theme_registry_alter(&$theme_registry) { unset($theme_registry['footnote_list']['function']); // $theme_registry['footnote_list']['function'] = 'bibcite_footnotes_theme_footnote_list'; $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'] = []; }