$plugin_definition return NULL causes error in php7.4

Created on 4 November 2020, over 4 years ago
Updated 14 September 2024, 8 months ago

Problem/Motivation

Recently I am upgrading php from 7.2 to 7.4 in our Drupal 8.8.10 site. I see a few errors incurring during the phpunit tests in our custom modules. Here is the example error logs

/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/modules/system/system.module:1483
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php:403
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:347
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php:500
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php:454
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:263
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Entity/EntityBase.php:395
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php:613
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Config/ConfigInstaller.php:382
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/Config/ConfigInstaller.php:148
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php:75
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/core/tests/Drupal/KernelTests/KernelTestBase.php:688
/home/jenkins/workspace/feature-FOX-2616-upgrade-php-7.4/docroot/modules/custom/ea_analytics/tests/src/Kernel/FloodlightValidationTest.php:53

In line 53 the script is try to install config during the test

    $this->installConfig(['ea_core_test']);

It turns out the error is thrown in the hook function system_entity_form_display_presave when $plugin_definition is NULL


function system_entity_form_display_presave(EntityFormDisplayInterface $display) {
  /** @var \Drupal\Core\Field\WidgetPluginManager $field_widget_manager */
  $field_widget_manager = \Drupal::service('plugin.manager.field.widget');

  foreach ($display->getComponents() as $field_name => $component) {
    if (empty($component['type'])) {
      continue;
    }

    $plugin_definition = $field_widget_manager->getDefinition($component['type'], FALSE);
    if (!is_a($plugin_definition['class'], EntityReferenceAutocompleteWidget::class, TRUE)) {
      continue;
    }

    if (!isset($component['settings']['match_limit'])) {
      @trigger_error(sprintf('Any entity_reference_autocomplete component of an entity_form_display must have a match_limit setting. The %s field on the %s form display is missing it. This BC layer will be removed before 9.0.0. See https://www.drupal.org/node/2863188', $field_name, $display->id()), E_USER_DEPRECATED);
      $component['settings']['match_limit'] = 10;
      $display->setComponent($field_name, $component);
    }
  }
}

The similar issue was discussed in https://www.drupal.org/project/drupal/issues/3086374#comment-13324523 . However this has not been addressed yet and system_entity_form_display_presave has also been deprecated in Drupal 9.0.x in https://www.drupal.org/project/drupal/issues/3086388

Steps to reproduce

- Use php 7.4
- Run unit test with installConfig.

Proposed resolution

Check if $plugin_definition is NULL.

Remaining tasks

When I search ->getDefinition($component['type'], FALSE) I can see same issue also exists in system.post_update.php and text.post_update.php files in 8.8.x and 8.9.x and the issue exists in text.post_update.php files in 9.0.x

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

🐛 Bug report
Status

Closed: works as designed

Version

11.0 🔥

Component
System 

Last updated about 9 hours ago

No maintainer
Created by

🇦🇺Australia eric.chenchao

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    There has been no response to #7 asking for tests to show the bug in core. Further, this is about using PHP 7.4, which is no longer supported.
    Therefore, I am closing this issue.

Production build 0.71.5 2024