Problem/Motivation
If more than 26 auto-numbered footnotes occur on a page, the following warning is thrown:
[warning] Undefined array key 26 FootnotesFilter.php:421
Steps to reproduce
Create a node with more than 26 footnotes. For each footnote, leave the footnote number field blank. Then put the following in a script and execute it using drush php:script:
use Drupal\node\Entity\Node;
ini_set('error_reporting', E_ALL);
$view_builder = Drupal::entityTypeManager()->getViewBuilder('node');
/** @var \Drupal\Core\Render\Renderer $renderer */
$renderer = Drupal::service('renderer');
$query = Drupal::database()->select('node__body', 'b')->fields('b', ['entity_id']);
$query->addExpression('ROUND((CHAR_LENGTH(body_value) - CHAR_LENGTH(REPLACE(body_value, \'<footnotes\', \'\')))/10)', 'fn_count');
$query->having('fn_count > 26');
$nids = $query->execute()->fetchCol();
$nodes = Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);
foreach ($nodes as $node) {
$renderer->renderInIsolation($view_builder->view($node));
}
Proposed resolution
src/Plugin/Filter/FootnotesFilter.php has this code starting at line 416 (in 4.0.0-rc1):
$alphabet = range('a', 'z');
$counter = 0;
// Assign 'a', 'b', 'c' suffixes tentatively.
foreach (self::$storedFootnotes[$key] as &$stored_footnote) {
$stored_footnote['backlink_value'] = $stored_footnote['value'] . $alphabet[$counter];
$counter++;
}
The $alphabet range can only handle 26 footnotes. We need to have a more robust way of generating backlink values. Maybe instead of using $alphabet[$counter] we do something like '-' . $counter?
Remaining tasks
Commit and release the proposed fix.
User interface changes
None.
API changes
None.
Data model changes
None,
Issue fork footnotes-3590374
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
daniel_j commentedComment #3
scott_euser commentedSo greater than 26 identical footnotes that should be grouped together into a single reference right?
Just because I know it works fine with 1000s of footnotes eg https://internationalaisafetyreport.org/publication/international-ai-saf...
I guess needs to be like Excel/Sheets, ie move to aa, ab, etc?
Comment #4
daniel_j commentedIf you leave the footnote number blank for all 27 of your footnotes (with the expectation that the module will auto-number them), it triggers this bug. I'll update the description now.
Comment #5
daniel_j commentedThat is to say, this is triggered when
$footnote['value']is blank. Is that indicative of a larger issue? I have a fix that appears to work locally.Comment #7
scott_euser commentedHmmm maybe, it should be doing 1, 2, 3, 4, 5 etc and only if you have collapse identical ones enabled, then eg if 2 are the same, you might have 1a, 1b, 2, 3, 4 as backlinks (so 1a going to first instance of the identical reference, 1b going to second instance). If I understand you right, you've gotten to a situation not where you have 26 identical ones, but that there is some bug where it's missing the differentiation between unique references and essentially grouping them all together without a number and just doing a b c etc (ie, just the suffices)
Comment #8
daniel_j commented@scott_euser Well, with my patch, it is not generating warnings AND it is showing all the footnotes correctly. But yes, it would seem that there is some logic error going on.
Comment #9
scott_euser commentedThat'd be a breaking change of course so not something I could merge (as can also be seen by the test failure).
For me to understand it better, what does your references output look like before (eg at less than 25 items)?
Comment #11
scott_euser commentedAha I see, it stores them temporarily there even if the texts are different. After storing it then compares the texts and shifts them out if they aren't identical. That tentative moment leads to your warning. Working on an MR to sort that doesn't cause breaking changes + adds additional test coverage
Comment #12
scott_euser commentedComment #14
daniel_j commentedLooks beautiful to me. 👍🏻
Comment #16
scott_euser commentedGreat thanks for raising and all the details!