Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Hello everyone, I came across this error when switching to php 8 the page returns an unexpected error:500, and in recent log messages print an error:
TypeError: Cannot access offset of type string on string in ctools_content_select_context() (line 812 of /ctools/includes/content.inc).
In code it preview like this:
if (empty($conf['context'])) {
$filtered = ctools_context_filter($contexts, $subtype_info['required context']);
if ($filtered) {
$keys = array_keys($filtered);
$conf['context'] = array_shift($keys);//812 line
}
}
in this case it is worth checking for empty below on line 817
if (empty($conf['context'])) {
return;
}
Proposed resolution
This is why you need to check $conf for an array:
if (is_array($conf) && empty($conf['context'])) {
Comments
Comment #2
Igumnov_aleksey CreditAttribution: Igumnov_aleksey at EPAM Systems commentedComment #3
Liam MorlandComment #4
Igumnov_aleksey CreditAttribution: Igumnov_aleksey at EPAM Systems commentedComment #5
Igumnov_aleksey CreditAttribution: Igumnov_aleksey at EPAM Systems commentedComment #6
joelpittetPlease try a newer version of ctools as this issue may already be resolved.
Also, the error needs a stack trace because why is $conf a string, where is that variable being assigned a string value, that is likely the part that needs fixing, maybe custom code or another module?