buildSPIFieldDefinitionUpdate() public method

Builds SPIFieldDefinition object using API FieldDefinitionUpdateStruct and API FieldDefinition.
public buildSPIFieldDefinitionUpdate ( eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct, eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition ) : eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
$fieldDefinitionUpdateStruct eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct
$fieldDefinition eZ\Publish\API\Repository\Values\ContentType\FieldDefinition
return eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
 /**
  * Update a field definition.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the field id in the update struct is not found or does not belong to the content type
  *                                                                        If the given identifier is used in an existing field of the given content type
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit a content type
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft the content type draft
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition the field definition which should be updated
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct
  */
 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;
     }
 }