Skip to content
Snippets Groups Projects

Resolve #3450120 "Make consistent"

Files

@@ -7,7 +7,6 @@ use Drupal\Component\Render\PlainTextOutput;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Random;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\Markup;
@@ -351,17 +350,13 @@ class FootnotesFilter extends FilterBase implements ContainerFactoryPluginInterf
}
// Build the render array for the footnote.
$random = new Random();
$random_string = $random->name(12);
$text_id = Crypt::hashBase64($text);
$text_id = str_replace('_', '', $text_id);
$footnote = [
'value' => $value,
'backlink_value' => $value,
'text' => $text instanceof MarkupInterface ? $text : Markup::create($text),
'text_clean' => PlainTextOutput::renderFromHtml((string) $text),
'fn_id' => 'footnote' . $value . '_' . $text_id . '_' . $random_string,
'ref_id' => 'footnoteref' . $value . '_' . $text_id . '_' . $random_string,
'fn_id' => 'footnote' . $value,
'ref_id' => 'footnoteref' . $value,
'instance' => 1,
'is_auto' => $is_auto,
'is_same_text' => TRUE,
@@ -374,14 +369,31 @@ class FootnotesFilter extends FilterBase implements ContainerFactoryPluginInterf
}
// Record the target text.
$this->storedFootnotes[$key][$footnote['fn_id']] = $footnote;
$fn_id = $footnote['fn_id'];
$counter = 1;
while (isset($this->storedFootnotes[$key][$fn_id])) {
$fn_id = $footnote['fn_id'] . '-' . $counter;
$counter++;
}
$this->storedFootnotes[$key][$fn_id] = $footnote;
// If there are multiple stored footnotes, set the backlink value.
if (count($this->storedFootnotes[$key]) > 1) {
$alphabet = range('a', 'z');
$counter = 0;
$stored_sub_keys = array_keys($this->storedFootnotes[$key]);
$first_sub_key = reset($stored_sub_keys);
foreach ($this->storedFootnotes[$key] as &$stored_footnote) {
$stored_footnote['backlink_value'] = $stored_footnote['value'] . $alphabet[$counter];
// Set reference and footnote ID's to be relative to the first footnote.
// So any subsequent footnotes after a first one like this:
// - #footnote1.
// Would become:
// - #footnote1-1.
// - #footnote1-2.
$stored_footnote['fn_id'] = $this->storedFootnotes[$key][$first_sub_key]['fn_id'] . '-' . $counter;
$stored_footnote['ref_id'] = $this->storedFootnotes[$key][$first_sub_key]['ref_id'] . '-' . $counter;
$counter++;
}
Loading