Error on checkIfChildIsGreaterThanOne() function

Created on 16 December 2024, 2 months ago

Problem/Motivation

We encountered this error in one project:
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 99 of modules/contrib/book/src/Controller/RouteAccessController.php).

Drupal\book\Controller\RouteAccessController->checkIfChildIsGreaterThanOne() (Line: 76)

Steps to reproduce

It seems like this happens when we have a multilingual book and when some translation is unpublished and other are published.

Proposed resolution

I found out this bug is easily fixed by replacing :

return count($child['below']) > 1;

with:

return !empty($child['below']) && count($child['below']) > 1;
πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡­πŸ‡°Hong Kong davidpetit

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024