Browse Source

WIP Add settings to hide backlink text.

mla_citations
Alexander O'Neill 6 years ago
parent
commit
1d57bff8d8
  1. 10
      bibcite_footnotes.module
  2. 15
      src/Plugin/Filter/ReferenceFootnotesFilter.php

10
bibcite_footnotes.module

@ -57,7 +57,8 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
];
$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) {
@ -68,12 +69,15 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
],
];
$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($fn['value'], $url)->toRenderable();
$link = Link::fromTextAndUrl(($dont_show_backlink_text && $reference_entity_id ? '^' : $fn['value']), $url)->toRenderable();
$build[] = $link;
}
else {
@ -95,8 +99,6 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
}
preg_match('/\[bibcite_reference:(\d*)\]/', $fn['text'], $matches);
$reference_entity_id = $matches[1];
if (!empty($reference_entity_id)) {
$reference_storage = \Drupal::entityTypeManager()
->getStorage('bibcite_reference')

15
src/Plugin/Filter/ReferenceFootnotesFilter.php

@ -80,6 +80,21 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
'#description' => $this->t('E.g., "Works Cited" for MLA style.'),
'#default_value' => $this->settings['references_section_label'],
];
$settings['reference_dont_show_backlink_text'] = [
'#type' => 'checkbox',
'#title' => $this->t("Don't show note 'value' text in reference list."),
'#description' => $this->t("Suitable for MLA-style citations, like (Smith, 33-22)"),
'#default_value' => $this->settings['reference_dont_show_backlink_text'],
];
$settings['reference_sort_by'] = [
'#type' => 'select',
'#title' => $this->t("Sort references list by"),
'#options' => [
'appearance' => $this->t("Appearance in text"),
'contributor_surname' => $this->t("Contributor surname"),
],
'#default_value' => $this->settings['reference_sort_by'],
];
return $settings;
}

Loading…
Cancel
Save