- 🇮🇹Italy apaderno Brescia, 🇮🇹
Notice that Trying to access array offset on value of type null means, for example, accessing
$formatter_type['module']
when$formatter_type
isNULL
.
I am not sure that setting$display['module']
to an empty string is much helpful, in that case. It could be helpful if it were be possible to set$display['module']
to a default module name, for example, for which invoking a hook would be later possible. - 🇮🇹Italy frazac
#5 does not work for me.
Still receiving the error on both remote production and dev server.
Warning: Trying to access array offset on value of type null in ctools_context_handler_get_render_handler() (line 68 of /home/.../sites/all/modules/ctools/includes/context-task-handler.inc).
Drupal 7.101
PHP 8.1.28 - 🇸🇰Slovakia poker10
@frazac Not sure your warning is caused by the Drupal core, as it is in the ctools module. You can check a similar issue here: #1244434: Notice: Undefined index: handler type in ctools_context_handler_get_render_handler() (line 67 → , maybe it could help.
- 🇮🇹Italy apaderno Brescia, 🇮🇹
I think the patch is just hiding a bigger issue.
Why is$formatter_type
NULL
? If it isNULL
, does continuing as nothing happened make sense? - 🇮🇹Italy apaderno Brescia, 🇮🇹
As a side note, the line containing
$display['module'] = $formatter_type['module'];
is line 648, now. - 🇮🇹Italy apaderno Brescia, 🇮🇹
Let's try to understand what exactly happens that makes
$formatter_type
set toNULL
(or not initialized to a correct value).The code containing the line causing that warning is the following one.
$display += array( 'label' => 'above', 'type' => isset($field_type['default_formatter']) ? $field_type['default_formatter'] : 'hidden', 'settings' => array(), ); if ($display['type'] != 'hidden') { $formatter_type = field_info_formatter_types($display['type']); $display['module'] = $formatter_type['module']; $display['settings'] += field_info_formatter_settings($display['type']); }
$formatter_type
can beNULL
becausefield_info_formatter_types()
did not find information about the$field_type['default_formatter']
formatter or the cache used by_field_info_collate_types()
got corrupted. In the case$field_type['default_formatter']
is an empty string,field_info_formatter_types()
would return an array with information about all the formatters (and probably cause other issues). - Merge request !8418Issue #3314719: Notice: Trying to access array offset on value of type null in... → (Open) created by apaderno
- Open on Drupal.org →Environment: PHP 8.1 & MySQL 5.7last update
5 months ago Waiting for branch to pass - Open on Drupal.org →Environment: PHP 8.1 & MySQL 5.7last update
5 months ago Waiting for branch to pass - Open on Drupal.org →Environment: PHP 8.1 & MySQL 5.7last update
5 months ago Waiting for branch to pass - 🇮🇹Italy apaderno Brescia, 🇮🇹
I changed the code to the following one.
if ($display['type'] != 'hidden') { $formatter_type = field_info_formatter_types($display['type']); if ($formatter_type) { $display['module'] = $formatter_type['module']; $display['settings'] += field_info_formatter_settings($display['type']); } }
The reason is that:
- If the formatter has not been found, we do not know which module implements it. Leaving
$formatter_type['module']
not set is probably the more correct way to say that. - If the formatter has not been found,
field_info_formatter_settings()
returns an empty array. Executing$display['settings'] += field_info_formatter_settings($display['type']);
is perfectly useless, since$display['settings']
has been already initialized to an empty array.
- If the formatter has not been found, we do not know which module implements it. Leaving