Problem/Motivation

I was using the Migrate Drupal UI module 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 $field_settings['handler_settings']['sort'], is not empty 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 me 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

Issue fork drupal-3537909

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

danrod created an issue. See original summary.

danrod’s picture

Issue summary: View changes
danrod’s picture

Issue summary: View changes
quietone’s picture

Version: 11.2.x-dev » 11.x-dev

In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies.

danrod’s picture

Thanks @quietone , forgot about that.
I created a MR, I guess it might need tests or more work, for now I leave as it is and It solved my migration issue.

danrod’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Think we will need steps to reproduce. Typically just putting an isset() or empty() check can be masking a larger issue.

danrod’s picture

I'll debug the migration process and see if I can reproduce the steps.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Needs work » Closed (won't fix)

The Migrate Drupal Module and Migrate Drupal UI are deprecated and they are not in Drupal 12.0.0.

Issues for these modules should now be on the 11.x branch. And the changes are limited to critical and major bug fixes. Other changes are allowed at the discretion of the core Release Managers in consultation with the Migrate subsystem maintainers.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.