Skip to content

Commit

Permalink
fixup: handle single value asset parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Mar 27, 2024
1 parent 6b14348 commit b5a24a2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions modules/core/log/farm_log.module
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ function farm_log_entity_prepare_form(EntityInterface $entity, $operation, FormS
$query = \Drupal::request()->query;

// Prepopulate the log asset field.
$asset_ids = $query->all('asset');
if (!empty($asset_ids)) {
if ($query->has('asset')) {

// Get asset IDs. We can't use $query->get('asset') or $query->all('asset')
// because those throw a client error if the parameter is not the expected
// cardinality (single value vs array of values).
$params = $query->all();
$asset_ids = $params['asset'];
if (!is_array($asset_ids)) {
$asset_ids = [$asset_ids];
}

/** @var \Drupal\Core\Field\EntityReferenceFieldItemList $asset_field */
$asset_field = $entity->get('asset');

Expand Down

0 comments on commit b5a24a2

Please sign in to comment.