Problem/Motivation
When the value for a unique target happens to be an array instead of a string, you'll get a \Drupal\Core\Database\InvalidQueryException on Drupal 11.
Steps to reproduce
- Install Feeds Tamper.
- Create a feed type.
- Map to a field. Set the field target as 'unique'.
- Add the Tamper "Explode" to this field.
When importing data now, the Tamper plugin "Explode" will turn the value for the field in question into an array. This happens even if the character that is used to split the value into multiple values does not appear in the value.
Simplified code example:
$value = 'Foo';
$new_value = explode('|', $value);
$new_value will equal to ['Foo'].
On Drupal 10, this will result into a deprecation warning:
Calling Drupal\Core\Database\Query\Condition::condition() without an array compatible operator is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3350985
But an exception on Drupal 11:
Drupal\Core\Database\InvalidQueryException: Calling Drupal\Core\Database\Query\Condition::condition() without an array compatible operator is not supported. See https://www.drupal.org/node/3350985
Proposed resolution
Attempt to cast the value for the unique query in \Drupal\feeds\Plugin\Type\Target\FieldTargetBase::getUniqueValue() to a string before passing it to Drupal\Core\Database\Query\Condition::condition().
Remaining tasks
- Review
- Commit
User interface changes
None.
API changes
Using multiple values to find an existing entity will no longer be supported. Because of the change in #2823910: DBTNG/EQ condition works inconsistently with arrays this would already no longer work since Drupal 10.1. When Feeds receives multiple values, it will pick the first one on the list to find the existing entity.
Data model changes
None.
Code will follow.
Issue fork feeds-3470963
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 #3
megachrizComment #5
megachrizI merged the code!