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

Command icon 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

daniel_j created an issue. See original summary.

daniel_j’s picture

Issue summary: View changes
scott_euser’s picture

So 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?

daniel_j’s picture

Issue summary: View changes

If 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.

daniel_j’s picture

That 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.

scott_euser’s picture

Hmmm 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)

daniel_j’s picture

@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.

scott_euser’s picture

That'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)?

scott_euser’s picture

Aha 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

scott_euser’s picture

Version: 4.0.0-rc1 » 4.0.x-dev
Status: Active » Needs review

scott_euser changed the visibility of the branch 3590374-warning-when- to hidden.

daniel_j’s picture

Looks beautiful to me. 👍🏻

  • scott_euser committed e0fff024 on 4.0.x
    fix: #3590374 Warning when > 26 footnotes with automatic numbering due...
scott_euser’s picture

Status: Needs review » Fixed

Great thanks for raising and all the details!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.