TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 51 of /web/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php)

Created on 24 July 2025, 12 days ago

Problem/Motivation

I was using the Migrate Drupal UI to migrate an old Drupal 7 with a few content types and mostly a huge quantity of users, and I ran into this 500 error:

TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 51 of /var/www/html/web/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php

#0 /var/www/html/web/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php(51): array_filter()
#1 /var/www/html/web/core/modules/migrate/src/MigrateExecutable.php(456): Drupal\field\Plugin\migrate\process\d7\FieldInstanceSettings->transform()
#2 /var/www/html/web/core/modules/migrate/src/MigrateExecutable.php(223): Drupal\migrate\MigrateExecutable->processPipeline()
#3 /var/www/html/web/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php(140): Drupal\migrate\MigrateExecutable->import()
#4 /var/www/html/web/core/includes/batch.inc(298): Drupal\migrate_drupal_ui\Batch\MigrateUpgradeImportBatch::run()
#5 /var/www/html/web/core/includes/batch.inc(139): _batch_process()
#6 /var/www/html/web/core/includes/batch.inc(95): _batch_do()
......

Steps to reproduce

Not sure what exactly what triggered this, I'm just reporting this and hoping that someone ran into the same problem before.

Proposed resolution

If we look at the file web/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php line 51:

    // Get entityreference handler settings from source field configuration.
    if ($row->getSourceProperty('type') == "entityreference") {
      $field_settings = $field_data['settings'];
      $instance_settings['handler'] = 'default:' . $field_settings['target_type'];
      // Transform the sort settings to D8 structure.
      $sort = [
        'field' => '_none',
        'direction' => 'ASC',
      ];
      if (i!empty(array_filter($field_settings['handler_settings']['sort']))) {
        if ($field_settings['handler_settings']['sort']['type'] == "property") {

it checks if the array element is not empty $field_settings['handler_settings']['sort'], but it can also be NULL (if $field_data['settings'] is also NULL), so a proper validation could be:

      if (isset($field_settings['handler_settings']['sort']) && !empty(array_filter($field_settings['handler_settings']['sort']))) {

This checks that $field_settings['handler_settings']['sort'] has data, even if it's an empty array, is not NULL

Again, this happened to be during the migration from an older D7 site to D11.2 site, not sure if it needs to be included in the codebase, but it's worth to mention

Remaining tasks

N/A

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

πŸ› Bug report
Status

Active

Version

11.2 πŸ”₯

Component

migration system

Created by

πŸ‡¨πŸ‡¦Canada danrod Ottawa

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024