diff --git a/src/Plugin/Filter/FootnotesFilter.php b/src/Plugin/Filter/FootnotesFilter.php index e88519c..ae44931 100644 --- a/src/Plugin/Filter/FootnotesFilter.php +++ b/src/Plugin/Filter/FootnotesFilter.php @@ -20,6 +20,7 @@ use Drupal\filter\Plugin\FilterBase; * cache = FALSE, * settings = { * "footnotes_collapse" = FALSE, + * "footnotes_ordered_ids" = FALSE, * "footnotes_html" = FALSE, * "footnotes_css" = TRUE * }, @@ -171,6 +172,7 @@ class FootnotesFilter extends FilterBase { */ protected function replaceCallback($matches, $op = '') { static $opt_collapse = 0; + static $opt_ordered_ids = 0; static $opt_html = 0; static $n = 0; static $store_matches = []; @@ -180,6 +182,7 @@ class FootnotesFilter extends FilterBase { if ($op == 'prepare') { // In the 'prepare' case, the first argument contains the options to use. // The name 'matches' is incorrect, we just use the variable anyway. + $opt_ordered_ids = $matches['footnotes_ordered_ids']; $opt_collapse = $matches['footnotes_collapse']; $opt_html = $matches['footnotes_html']; return 0; @@ -302,15 +305,27 @@ class FootnotesFilter extends FilterBase { } // Create a footnote item as an array. - $fn = [ - 'value' => $value, - 'text' => $opt_html ? html_entity_decode($text) : $text, - 'text_clean' => $text_clean, - 'fn_id' => 'footnote' . $value_id . '_' . $randstr, - 'ref_id' => 'footnoteref' . $value_id . '_' . $randstr, - 'instances' => $instances, - 'instance' => $instance, - ]; + if(empty($opt_ordered_ids)) { + $fn = [ + 'value' => $value, + 'text' => $opt_html ? html_entity_decode($text) : $text, + 'text_clean' => $text_clean, + 'fn_id' => 'footnote' . $value_id . '_' . $randstr, + 'ref_id' => 'footnoteref' . $value_id . '_' . $randstr, + 'instances' => $instances, + 'instance' => $instance, + ]; + } else { + $fn = [ + 'value' => $value, + 'text' => $opt_html ? html_entity_decode($text) : $text, + 'text_clean' => $text_clean, + 'fn_id' => 'footnote' . $value_id, + 'ref_id' => 'footnoteref' . $value_id, + 'instances' => $instances, + 'instance' => $instance, + ]; + } // We now allow to repeat the footnote value label, in which case the link // to the previously existing footnote is returned. Content of the current @@ -436,6 +451,12 @@ class FootnotesFilter extends FilterBase { '#default_value' => $this->settings['footnotes_css'] ?? TRUE, '#description' => $this->t('Uncheck this option to remove footnotes CSS.'), ]; + $settings['footnotes_ordered_ids'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Create linkable IDs based on footnote number.'), + '#default_value' => $this->settings['footnotes_ordered_ids'] ?? FALSE, + '#description' => $this->t('Allows stable IDs which can be linked to, for content where footnote count and order do not change.
Do not check if a page can contain more than one footnoted node, where random strings are needed to avoid duplicate IDs.'), + ]; return $settings; }