public updateContentTypeDraftFieldDefinition ( $contentTypeId, $fieldDefinitionId, |
||
$contentTypeId | ||
$fieldDefinitionId | ||
$request | ||
Результат |
public function updateContentTypeDraftFieldDefinition($contentTypeId, $fieldDefinitionId, Request $request)
{
$contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
$fieldDefinitionUpdate = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type'), 'Url' => $request->getPathInfo()), $request->getContent()));
$fieldDefinition = null;
foreach ($contentTypeDraft->getFieldDefinitions() as $fieldDef) {
if ($fieldDef->id == $fieldDefinitionId) {
$fieldDefinition = $fieldDef;
}
}
if ($fieldDefinition === null) {
throw new Exceptions\NotFoundException("Field definition not found: '{$request->getPathInfo()}'.");
}
try {
$this->contentTypeService->updateFieldDefinition($contentTypeDraft, $fieldDefinition, $fieldDefinitionUpdate);
} catch (InvalidArgumentException $e) {
throw new ForbiddenException($e->getMessage());
}
$updatedDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
foreach ($updatedDraft->getFieldDefinitions() as $fieldDef) {
if ($fieldDef->id == $fieldDefinitionId) {
return new Values\RestFieldDefinition($updatedDraft, $fieldDef);
}
}
throw new Exceptions\NotFoundException("Field definition not found: '{$request->getPathInfo()}'.");
}