public function updateFieldDefinition(APIContentTypeDraft $contentTypeDraft, APIFieldDefinition $fieldDefinition, FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct)
{
if ($this->repository->hasAccess('class', 'update') !== true) {
throw new UnauthorizedException('ContentType', 'update');
}
$loadedContentTypeDraft = $this->loadContentTypeDraft($contentTypeDraft->id);
$foundFieldId = false;
foreach ($loadedContentTypeDraft->fieldDefinitions as $existingFieldDefinition) {
if ($existingFieldDefinition->id == $fieldDefinition->id) {
$foundFieldId = true;
} elseif ($existingFieldDefinition->identifier == $fieldDefinitionUpdateStruct->identifier) {
throw new InvalidArgumentException('$fieldDefinitionUpdateStruct', "Another FieldDefinition with identifier '{$fieldDefinitionUpdateStruct->identifier}' exists in the ContentType");
}
}
if (!$foundFieldId) {
throw new InvalidArgumentException('$fieldDefinition', 'The given FieldDefinition does not belong to the ContentType');
}
$spiFieldDefinitionUpdateStruct = $this->contentTypeDomainMapper->buildSPIFieldDefinitionUpdate($fieldDefinitionUpdateStruct, $fieldDefinition);
$this->repository->beginTransaction();
try {
$this->contentTypeHandler->updateFieldDefinition($contentTypeDraft->id, SPIContentType::STATUS_DRAFT, $spiFieldDefinitionUpdateStruct);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}