diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index 1bad342..60a6837 100644 --- a/bibcite_footnotes.module +++ b/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') diff --git a/src/Plugin/Filter/ReferenceFootnotesFilter.php b/src/Plugin/Filter/ReferenceFootnotesFilter.php index 7903726..c7d498a 100644 --- a/src/Plugin/Filter/ReferenceFootnotesFilter.php +++ b/src/Plugin/Filter/ReferenceFootnotesFilter.php @@ -78,7 +78,22 @@ class ReferenceFootnotesFilter extends FootnotesFilter { '#type' => 'textfield', '#title' => $this->t('References section label'), '#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; }