PHP 8 ValueError: max(): Argument #1 ($value) must contain at least one element in max() in link.migrate.inc

Created on 16 April 2023, over 1 year ago
Updated 31 August 2024, 3 months ago

Problem/Motivation

When migrating multi-value link fields, if $values parameter is empty import fails with PHP ValueError: max(): Argument #1 ($value) must contain at least one element in max().

Steps to reproduce

Configure a migration with multi-value (single probably has the same issue but I did not test single value) link fields:

    $this->addFieldMapping('field_links', 'source_field_urls');
    $this->addFieldMapping('field_links:title', 'source_field_titles');
    $this->addFieldMapping('field_links:attributes', 'source_field_attributes');

Where source_field_* are all empty arrays.

Run migrate import with drush mi [name of migration]. Migration will fail with php: ValueError: max(): Argument #1 ($value) must contain at least one element in max().

Proposed resolution

It might not be as simple as returning NULL early from MigrateLinkFieldHandler::prepare() if parameter $values is empty, because link fields allow url to be optional. One option would be to return early if both titles and urls are empty. For more complex settings (where title or url is optional) the smarter solution may be to check the field settings to determine which elements are optional, and then decide what to do.

πŸ› Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States lwalley

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

Comments & Activities

Production build 0.71.5 2024