My Drupal 11.4.1 installation has the filebrowser module installed as well as the solo theme. When trying to access directories managed by filebrowser, solo crashes with this error:

Uncaught PHP Exception TypeError: "str_contains(): Argument #1 ($haystack) must be of type string, array given" at .../drupal/web/themes/solo/includes/_solo_theme_preprocess.inc line 2142

This is because the $container_id variable defined in solo_preprocess_container() is an array:

Array ( [0] => form-action-actions-wrapper )

A way to fix this problem is to extract the value contained in the array if $container_id is not a string. Patch attached.

CommentFileSizeAuthor
solo_filebrowser_compat.patch483 byteslpsolit

Comments

lpsolit created an issue. See original summary.

flashwebcenter’s picture

Status: Needs review » Fixed

Hello,
Thanks again for the patch, your diagnosis was spot on, and it pointed straight to the fix.
I ended up using a slightly more defensive variation of your approach:

$container_id = $variables['attributes']['id'] ?? '';
if (is_array($container_id)) {
$container_id = (string) (reset($container_id) ?: '');
}
if ($container_id !== '' && str_contains($container_id, 'ajax-wrapper')) {

It does the same thing as your patch for the case you hit, and also covers a few edge cases: arrays without a numeric 0 key (associative or re-indexed), empty arrays, and non-string values. So str_contains() always receives a valid string.
While I was in there I also audited the rest of the theme for the same pattern and hardened one other spot (stripos() on $element['#name']) that could throw the identical TypeError if a module supplied an array.

This will be in the next release. Really appreciate you taking the time to report it and provide a patch.
Best wishes,
Alaa

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.