/**
  * @param Request $request
  * @param PrivateMessage $privateMessage
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  * @Route("/{id}", requirements={"id": "\d+"}, name="delete_private_message")
  * @Method("DELETE")
  */
 public function deleteAction(Request $request, PrivateMessage $privateMessage)
 {
     $form = $this->get('app.delete_form_service')->createEntityDeleteForm($privateMessage->getId(), 'delete_private_message');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->remove($privateMessage);
         $em->flush();
     }
     return $this->redirect($this->generateUrl('admin_private_messages'));
 }
 /**
  * @Route("/{id}", requirements={"id": "\d+"}, name="show_private_message")
  * @Method("GET")
  * @Security("is_granted('read_message', privateMessage)")
  * @Template("AppBundle:shop/PrivateMessage:show.html.twig")
  * @param PrivateMessage $privateMessage
  * @return array
  */
 public function showAction(PrivateMessage $privateMessage)
 {
     if (!$privateMessage->getIsViewed() && $this->getUser() === $privateMessage->getRecipient()) {
         $this->get('app.private_messages_service')->setPrivateMessagesRead([$privateMessage]);
     }
     $newPrivateMessage = new PrivateMessage();
     $form = $this->createForm(PrivateMessageType::class, $newPrivateMessage, ['action' => $this->generateUrl('create_private_message', ['id' => $privateMessage->getRecipient()->getId()]), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'private_message.send']);
     return ['privateMessage' => $privateMessage, 'form' => $form->createView()];
 }
 /**
  * @param PrivateMessage $privateMessage
  * @param User $user
  * @return bool
  */
 private function canEditSentMessage(PrivateMessage $privateMessage, User $user)
 {
     return $privateMessage->getSender() === $user;
 }