The Drupal system I have inherited is throwing a large number of PHP warnings into the logs that look like this:
Warning: array_flip(): Can only flip STRING and INTEGER values in Drupal\Core\Entity\EntityStorageBase->loadMultiple()
I have spent some time running it through a debugger and reading existing tickets, this is what I have found:
There seem to be a number of circumstances that can lead to this error. Some error reports I have seen talk about it being caused by an ID value being turned into a float rather than an int, due to an earlier call to floor().
In my case the error occurs in the loadMultiple() method when an ID arrives wrapped in a Drupal\Core\Render\Markup object rather than being a plain integer or string.
In all cases I've seen, the value is correct, but is just not presented in a format that array_flip can handle.
It therefore seems to me that an appropriate fix would be to add a little pre-processing to normalise the array to contain only strings or integers.
I therefore propose that we add the following code to the loadMultiple() method, before the call to array_flip():
if ($ids) {
foreach ($ids as $key=>$value) {
if (!is_string($value) && !is_integer($value)) {
$ids[$key] = (string)$value;
}
}
}