Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Fixed bug in possible types
Browse files Browse the repository at this point in the history
  • Loading branch information
rratsun committed Jan 19, 2023
1 parent e1e848b commit 8a48311
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/Repositories/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,18 @@ protected function beforeSave(Entity $entity, array $options = [])
throw new BadRequest($this->getInjection('language')->translate('noAssetTypeProvided', 'exceptions', 'Asset'));
}

$entity->set('type', $possibleTypes);
$options = $this->getMetadata()->get(['entityDefs', 'Asset', 'fields', 'type', 'options'], []);
$optionsIds = $this->getMetadata()->get(['entityDefs', 'Asset', 'fields', 'type', 'optionsIds'], []);

$possibleTypesIds = [];
foreach ($possibleTypes as $possibleType) {
$key = array_search($possibleType, $options);
if ($key !== false && isset($optionsIds[$key])) {
$possibleTypesIds[] = $optionsIds[$key];
}
}

$entity->set('type', $possibleTypesIds);
}

// validate asset if type changed
Expand Down

0 comments on commit 8a48311

Please sign in to comment.