public function createObjectState(APIObjectStateGroup $objectStateGroup, ObjectStateCreateStruct $objectStateCreateStruct)
{
if ($this->repository->hasAccess('state', 'administrate') !== true) {
throw new UnauthorizedException('state', 'administrate');
}
$inputStruct = $this->buildCreateInputStruct($objectStateCreateStruct->identifier, $objectStateCreateStruct->defaultLanguageCode, $objectStateCreateStruct->names, $objectStateCreateStruct->descriptions);
try {
$this->objectStateHandler->loadByIdentifier($inputStruct->identifier, $objectStateGroup->id);
throw new InvalidArgumentException('objectStateCreateStruct', 'Object state with provided identifier already exists in provided object state group');
} catch (APINotFoundException $e) {
// Do nothing
}
$this->repository->beginTransaction();
try {
$spiObjectState = $this->objectStateHandler->create($objectStateGroup->id, $inputStruct);
if (is_int($objectStateCreateStruct->priority)) {
$this->objectStateHandler->setPriority($spiObjectState->id, $objectStateCreateStruct->priority);
// Reload the object state to have the updated priority,
// considering that priorities are always incremental within a group
$spiObjectState = $this->objectStateHandler->load($spiObjectState->id);
}
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
return $this->buildDomainObjectStateObject($spiObjectState);
}