From 9ff2456b73109a23a092cae4339839bc1fee4bf6 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 2 Nov 2018 07:33:52 -0300 Subject: [PATCH] WIP ibidem first steps --- .../Filter/ReferenceFootnotesFilter.php | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Plugin/Filter/ReferenceFootnotesFilter.php b/src/Plugin/Filter/ReferenceFootnotesFilter.php index 3b24eed..fcddbf7 100644 --- a/src/Plugin/Filter/ReferenceFootnotesFilter.php +++ b/src/Plugin/Filter/ReferenceFootnotesFilter.php @@ -18,6 +18,7 @@ use Drupal\footnotes\Plugin\Filter\FootnotesFilter; * cache = FALSE, * settings = { * "footnotes_collapse" = FALSE, + * "footnotes_ibid" = FALSE, * "notes_section_label" = "Notes", * "references_section_label" = "References" * }, @@ -66,10 +67,15 @@ class ReferenceFootnotesFilter extends FootnotesFilter { public function settingsForm(array $form, FormStateInterface $form_state) { $settings['footnotes_collapse'] = [ '#type' => 'checkbox', - '#title' => t('Collapse reference footnotes with identical content'), + '#title' => $this->t('Collapse reference footnotes with identical content'), '#default_value' => $this->settings['footnotes_collapse'], '#description' => t('If two reference footnotes have the exact same content, they will be collapsed into one as if using the same value="" attribute.'), ]; + $settings['footnotes_ibid'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Display subsequent instances of multiple references with \'Ibid.\''), + '#default_value' => $this->settings['footnotes_ibid'], + ]; $settings['notes_section_label'] = [ '#type' => 'textfield', '#title' => t('Notes section label'), @@ -133,6 +139,9 @@ class ReferenceFootnotesFilter extends FootnotesFilter { } if ($op == 'output footer') { + if ($this->settings['footnotes_ibid']) { + $this->ibidemify($store_matches); + } if (count($store_matches) > 0) { // Only if there are stored fn matches, pass the array of fns to be // themed as a list Drupal 7 requires we use "render element" which @@ -304,4 +313,24 @@ class ReferenceFootnotesFilter extends FootnotesFilter { } return $value; } + + protected function ibidemify(&$footnotes) { + $prev_reference_id = FALSE; + foreach ($footnotes as $index => $fn) { + if (!empty($fn['text'])) { + $prev_reference_id = FALSE; + continue; + } + if ($prev_reference_id) { + if ($fn['reference'] == $prev_reference_id) { + unset($footnotes[$index]['reference']); + $footnotes[$index]['text'] = $this->t('Ibid.'); + continue; + } + } + $prev_reference_id = $fn['reference']; // Could be empty, that's OK. + + } + ksm($footnotes); + } }