public function updateFieldDefinition($identifier, FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct)
 {
     $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($this->currentContentType);
     $this->contentTypeService->updateFieldDefinition($contentTypeDraft, $this->currentContentType->getFieldDefinition($identifier), $fieldDefinitionUpdateStruct);
     $this->contentTypeService->publishContentTypeDraft($contentTypeDraft);
     $this->currentContentType = $this->contentTypeService->loadContentTypeByIdentifier($this->currentContentType->identifier);
 }
 /**
  * Update content type definition and returns a draft
  *
  * @param array $data
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
  */
 private function getUpdatedDraft(array &$data)
 {
     $contentType = $this->contentTypeService->loadContentTypeByIdentifier($data['identifier']);
     $draft = $this->contentTypeService->createContentTypeDraft($contentType);
     // Update content type
     $struct = $this->contentTypeService->newContentTypeUpdateStruct($data);
     $this->fillValueObject($struct, $data);
     $diff = $this->diff->diff($contentType->fieldDefinitions, $data['field_definitions'], 'identifier');
     // @todo: introduce field updates (now only remove and add are supported)
     $this->updateDraftFields($draft, $diff, $data);
     $this->contentTypeService->updateContentTypeDraft($draft, $struct);
     return $draft;
 }
 public function updateContentTypeAction(Request $request, $contentTypeId, $languageCode = null)
 {
     $languageCode = $languageCode ?: $this->prioritizedLanguages[0];
     // First try to load the draft.
     // If it doesn't exist, create it.
     try {
         $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
     } catch (NotFoundException $e) {
         $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($this->contentTypeService->loadContentType($contentTypeId));
     }
     $contentTypeData = (new ContentTypeDraftMapper())->mapToFormData($contentTypeDraft);
     $form = $this->createForm('ezrepoforms_contenttype_update', $contentTypeData, ['languageCode' => $languageCode]);
     $actionUrl = $this->generateUrl('admin_contenttypeUpdate', ['contentTypeId' => $contentTypeId, 'languageCode' => $languageCode]);
     // Synchronize form and data.
     $form->handleRequest($request);
     $hasErrors = false;
     if ($form->isValid()) {
         $this->contentTypeActionDispatcher->dispatchFormAction($form, $contentTypeData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null, ['languageCode' => $languageCode]);
         if ($response = $this->contentTypeActionDispatcher->getResponse()) {
             return $response;
         }
         return $this->redirectAfterFormPost($actionUrl);
     } elseif ($form->isSubmitted()) {
         $hasErrors = true;
     }
     return $this->render('eZPlatformUIBundle:ContentType:update_content_type.html.twig', ['form' => $form->createView(), 'action_url' => $actionUrl, 'contentTypeName' => $contentTypeDraft->getName($languageCode), 'contentTypeDraft' => $contentTypeDraft, 'modifier' => $this->userService->loadUser($contentTypeDraft->modifierId), 'languageCode' => $languageCode, 'hasErrors' => $hasErrors]);
 }
 /**
  * Creates a draft and updates it with the given data
  *
  * @param $contentTypeId
  *
  * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
  * @return \eZ\Publish\Core\REST\Server\Values\CreatedContentType
  */
 public function createContentTypeDraft($contentTypeId, Request $request)
 {
     $contentType = $this->contentTypeService->loadContentType($contentTypeId);
     try {
         $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($contentType);
     } catch (BadStateException $e) {
         throw new ForbiddenException($e->getMessage());
     }
     $contentTypeUpdateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
     try {
         $this->contentTypeService->updateContentTypeDraft($contentTypeDraft, $contentTypeUpdateStruct);
     } catch (InvalidArgumentException $e) {
         throw new ForbiddenException($e->getMessage());
     }
     return new Values\CreatedContentType(array('contentType' => new Values\RestContentType($this->contentTypeService->loadContentTypeDraft($contentTypeDraft->id))));
 }
 /**
  * Creates a draft from an existing content type.
  *
  * This is a complete copy of the content
  * type which has the state STATUS_DRAFT.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit a content type
  * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If there is already a draft assigned to another user
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
  */
 public function createContentTypeDraft(ContentType $contentType)
 {
     $returnValue = $this->service->createContentTypeDraft($contentType);
     $this->signalDispatcher->emit(new CreateContentTypeDraftSignal(array('contentTypeId' => $contentType->id)));
     return $returnValue;
 }