Fix TypeError: Argument 1 passed to Drupal\Core\Entity\EntityStorageBase::loadMultiple() must be of the type array or null, string given.

This error occurs if ?asset=X is used instead of ?asset[]=X.
We can take a more defensive approach by automatically
wrapping the input in an array if it isn't already one.
This commit is contained in:
Michael Stenta 2021-09-06 10:54:44 -04:00
parent 345464c6ad
commit 08c50d7fde
1 changed files with 5 additions and 0 deletions

View File

@ -61,6 +61,11 @@ function farm_log_entity_prepare_form(EntityInterface $entity, $operation, FormS
/** @var \Drupal\Core\Field\EntityReferenceFieldItemList $asset_field */
$asset_field = $entity->get('asset');
// Wrap in an array, if necessary.
if (!is_array($asset_ids)) {
$asset_ids = [$asset_ids];
}
// Add each asset the user has view access to.
$assets = \Drupal::entityTypeManager()->getStorage('asset')->loadMultiple($asset_ids);
foreach ($assets as $asset) {