/** * Set/unset the sticky boolean on the given article. * This method is intended to be called by an Ajax request. * * @param Article $article * @return JsonResponse */ public function stickyAction(Article $article) { try { if ($article->getSticky()) { $article->setSticky(false); $response['sticky'] = false; } else { $article->setSticky(true); $response['sticky'] = true; } $em = $this->getDoctrine()->getManager(); $em->persist($article); $em->flush(); $response['success'] = true; } catch (\Exception $e) { $response = ['success' => false, 'code' => $e->getCode(), 'cause' => 'Det oppstod en feil.']; } return new JsonResponse($response); }