private function processForm($request, $topicId = null, $articleNumber = null, $languageCode = null)
{
$em = $this->get('em');
$topic = new Topic();
$statusCode = 201;
if ($topicId) {
$topic = $em->getRepository('Newscoop\\NewscoopBundle\\Entity\\Topic')->findOneById($topicId);
$statusCode = 200;
if (is_null($topic)) {
throw new NotFoundHttpException("Topic with ID: '" . $topicId . "' was not found");
}
}
$article = null;
if (!is_null($articleNumber) && !is_null($languageCode)) {
$article = $em->getRepository('Newscoop\\Entity\\Article')->getArticle($articleNumber, $languageCode)->getOneOrNullResult();
if (!$article) {
throw new NotFoundHttpException('Article with number:"' . $articleNumber . '" and language: "' . $languageCode . '" was not found.');
}
}
$form = $this->get('form.factory')->create(new TopicType(), $topic);
$form->handleRequest($request);
if ($form->isValid()) {
if ($article) {
$topic->addArticleTopic($article);
}
$locale = null;
if (!$topic->getTranslatableLocale()) {
$locale = $request->getLocale();
}
$topicService = $this->get('newscoop_newscoop.topic_service');
$topicService->saveNewTopic($topic, $locale);
$response = new Response();
$response->setStatusCode($statusCode);
$response->headers->set('X-Location', $this->generateUrl('newscoop_gimme_topics_gettopicbyid', array('id' => $topic->getId()), true));
return $response;
}
return $form;
}