Browse Source

WIP ibidem first steps

ibidem
Alexander O'Neill 6 years ago
parent
commit
9ff2456b73
  1. 31
      src/Plugin/Filter/ReferenceFootnotesFilter.php

31
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);
}
}

Loading…
Cancel
Save