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.
Issue fork link-3354440
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
Comment #2
lwalley commentedComment #4
lwalley commentedComment #5
dqdThanks for the report and MR. Since this is related to the fixed issue #3399967: PHP 8 Usage of max() with potential string values, can you or somebody else following this issue please test if this issue still persist and if so, could somebody please re-roll against latest dev? I will review and commit if required asap. Feel free to ping me on Slack any time.