Upgrade from Drupal 10.4.7 to Drupal 11.1.7 when no books are present

Created on 19 May 2025, 15 days ago

Problem/Motivation

TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 40 of modules/contrib/book/src/Access/BookNodeOutlineAccessCheck.php).

Steps to reproduce

Install drupal 10.4.7, book module, do not create any book nodes
Upgrade to drupal 11.1.7 , see wsod
exact use case: using wxt 5.4.2 vs 11.1.x

Proposed resolution

See patch and merge request

git diff src/Access/BookNodeOutlineAccessCheck.php
diff --git a/src/Access/BookNodeOutlineAccessCheck.php b/src/Access/BookNodeOutlineAccessCheck.php
index ec51149..0cf4e68 100644
--- a/src/Access/BookNodeOutlineAccessCheck.php
+++ b/src/Access/BookNodeOutlineAccessCheck.php
@@ -37,7 +37,8 @@ class BookNodeOutlineAccessCheck implements AccessInterface {
   public function access(NodeInterface $node): AccessResultInterface {
     // If content type is allowed book type, then check for 'add content to
     // books' permission.
-    if (in_array($node->getType(), $this->configFactory->get('book.settings')->get('allowed_types'))) {
+    $allowed_types = $this->configFactory->get('book.settings')->get('allowed_types') ?? [];
+    if (in_array($node->getType(), $allowed_types)) {
       return AccessResult::allowedIfHasPermission($this->currentUser, 'add content to books')
         ->orif(AccessResult::allowedIfHasPermission($this->currentUser, 'administer book outlines'));
     }

Remaining tasks

See patch and merge request

User interface changes

N/A

API changes

Fix

Data model changes

N/A

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇨🇦Canada joseph.olstad

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