Fix TOC API and filter for smart Table Of Contents (TOC) process of empty elements

Created on 11 April 2022, about 2 years ago
Updated 22 January 2023, over 1 year ago

Problem/Motivation

In src/TocBuilder.php, line 45

$dom_node = $dom->getElementById($item['id']);

The result can be null, so the following call
results in an "Error: Call to a member function hasAttributes() on null"

      // Get attributes.
      $attributes = [];
      if ($dom_node->hasAttributes()) {

Steps to reproduce

Drupal text format and filter will filter and process with TOC Filter and the TOC API
And the DOM will empty any h1, h2 ,h3 … from not allowed internal tags
Then the TOC API will have an empty element which brings the fatal error

Proposed resolution

e.g.

      $dom_node = $dom->getElementById($item['id']);
      if (is_null($dom_node)) {
        continue;
      }

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany jenger1965

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024