public function action(array $formValues, array $contenttype, $id, $new, $returnTo, $editReferrer)
{
$contentTypeSlug = $contenttype['slug'];
$repo = $this->em->getRepository($contentTypeSlug);
// If we have an ID now, this is an existing record
if ($id) {
$content = $repo->find($id);
$oldContent = clone $content;
$oldStatus = $content['status'];
} else {
$content = $repo->create(['contenttype' => $contentTypeSlug, 'status' => $contenttype['default_status']]);
$oldContent = null;
$oldStatus = 'draft';
}
// Don't allow spoofing the ID.
if ($content->getId() !== null && (int) $id !== $content->getId()) {
if ($returnTo === 'ajax') {
throw new AccessControlException("Don't try to spoof the id!");
}
$this->loggerFlash->error("Don't try to spoof the id!");
return new RedirectResponse($this->generateUrl('dashboard'));
}
$this->setPostedValues($content, $formValues, $contenttype);
$this->setTransitionStatus($content, $contentTypeSlug, $id, $oldStatus);
// Get the associated record change comment
$comment = isset($formValues['changelog-comment']) ? $formValues['changelog-comment'] : '';
// Save the record
return $this->saveContentRecord($content, $oldContent, $contenttype, $new, $comment, $returnTo, $editReferrer);
}