Error on checkIfChildIsGreaterThanOne() function
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3494135. -->
Reported by: [davidpetit](https://www.drupal.org/user/856744)
Related to !77
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>We encountered this error in one project:<br>
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).</p>
<p>Drupal\book\Controller\RouteAccessController->checkIfChildIsGreaterThanOne() (Line: 76)</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>It seems like this happens when we have a multilingual book and when some translation is unpublished and other are published.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>I found out this bug is easily fixed by replacing :</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br></span><span style="color: #007700">return </span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$child</span><span style="color: #007700">[</span><span style="color: #DD0000">'below'</span><span style="color: #007700">]) > </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br></span><span style="color: #0000BB">?></span></span></pre></div>
<p>with:</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br></span><span style="color: #007700">return !empty(</span><span style="color: #0000BB">$child</span><span style="color: #007700">[</span><span style="color: #DD0000">'below'</span><span style="color: #007700">]) && </span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$child</span><span style="color: #007700">[</span><span style="color: #DD0000">'below'</span><span style="color: #007700">]) > </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br></span><span style="color: #0000BB">?></span></span></pre></div>
issue