PHP 8.0 compatibility

Created on 15 June 2023, about 1 year ago
Updated 16 June 2023, about 1 year ago

Problem/Motivation

Warning: Trying to access array offset on value of type null in FieldInfo->prepareInstanceDisplay() (line 629 of /modules/field/field.info.class.inc).

reproduced when $field_type is equal to 'apachesolr_reference'

if ($display['type'] != 'hidden') {
   $formatter_type_info = field_info_formatter_types($display['type']); //returns null
   // Fall back to default formatter if formatter type is not available.
   if (!$formatter_type_info) {
      $display['type'] = $field_type_info['default_formatter'];
      $formatter_type_info = field_info_formatter_types($display['type']); //returns null
   }
   $display['module'] = $formatter_type_info['module'];// line 629
   // Fill in default settings for the formatter.
   $display['settings'] += field_info_formatter_settings($display['type']);
}

This happens because when we pass $display['type'] to the function field_info_formatter_types()

function field_info_formatter_types($formatter_type = NULL) {
  $info = _field_info_collate_types();
  $formatter_types = $info['formatter types'];
  if ($formatter_type) {
    if (isset($formatter_types[$formatter_type])) {
      return $formatter_types[$formatter_type];
    }
  }
  else {
    return $formatter_types;
  }
}

in $formatter_types it returns 'apachesolr_reference_content_formatter_label' in line 164.

function apachesolr_reference_field_info() {
  return array(
    'apachesolr_reference' => array(
      'label' => t('Apache SOLR Reference'),
      'description' => t('Provides a reference field to remote SOLR content'),
      'settings' => array(
        'solr_env' => apachesolr_default_environment(),
        'field_query' => '',
        'search_fields' => array(
          'id' => 'entity_id',
          'label' => 'label',
        ),
        'field_list' => '',
      ),
      'instance_settings' => array(),
      'default_widget' => 'apachesolr_reference_autocomplete',
      'default_formatter' => 'apachesolr_reference_content_formatter_label', //line 164
    ),
  );
}

but among the specified formats that are in the function apachesolr_reference_field_formatter_info () there is no such one, therefore, it should be considered that this error was originally, only for php 7.4, it was a notification, and for php 8.0 it is warning.

Proposed resolution

To solve this problem, I propose to change
'default_formatter' => 'apachesolr_reference_formatter_label',
to the one that is and this problem will be solved.

πŸ› Bug report
Status

Needs review

Version

1.5

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Igumnov_aleksey

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024