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. 17
      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'; $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'); $serializer = \Drupal::service('serializer');
foreach ($footnotes as $fn) { foreach ($footnotes as $fn) {
@ -68,12 +69,15 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
], ],
]; ];
$build = []; $build = [];
preg_match('/\[bibcite_reference:(\d*)\]/', $fn['text'], $matches);
$reference_entity_id = $matches[1];
if (!is_array($fn['ref_id'])) { if (!is_array($fn['ref_id'])) {
// Output normal footnote. // Output normal footnote.
$url = Url::fromUserInput('#' . $fn['ref_id'], ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-link']]); $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; $build[] = $link;
} }
else { 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)) { if (!empty($reference_entity_id)) {
$reference_storage = \Drupal::entityTypeManager() $reference_storage = \Drupal::entityTypeManager()
->getStorage('bibcite_reference') ->getStorage('bibcite_reference')

17
src/Plugin/Filter/ReferenceFootnotesFilter.php

@ -78,7 +78,22 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => $this->t('References section label'), '#title' => $this->t('References section label'),
'#description' => $this->t('E.g., "Works Cited" for MLA style.'), '#description' => $this->t('E.g., "Works Cited" for MLA style.'),
'#default_value' => $this->settings['references_section_label'], '#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; return $settings;
} }

Loading…
Cancel
Save