Ojs\JournalBundle\Controller\BoardController::deleteAction PHP Method

deleteAction() public method

Deletes a Board entity.
public deleteAction ( Request $request, Board $entity ) : RedirectResponse
$request Symfony\Component\HttpFoundation\Request
$entity Ojs\JournalBundle\Entity\Board
return Symfony\Component\HttpFoundation\RedirectResponse
    public function deleteAction(Request $request, Board $entity)
    {
        $journal = $this->get('ojs.journal_service')->getSelectedJournal();
        $eventDispatcher = $this->get('event_dispatcher');
        if (!$this->isGranted('DELETE', $journal, 'boards')) {
            throw new AccessDeniedException("You not authorized for delete this journal's boards!");
        }
        $em = $this->getDoctrine()->getManager();
        $csrf = $this->get('security.csrf.token_manager');
        $token = $csrf->getToken('ojs_journal_board' . $entity->getId());
        if ($token != $request->get('_token')) {
            throw new TokenNotFoundException("Token Not Found!");
        }
        $this->get('ojs_core.delete.service')->check($entity);
        $event = new JournalItemEvent($entity);
        $eventDispatcher->dispatch(BoardEvents::PRE_DELETE, $event);
        $em->remove($entity);
        $em->flush();
        $event = new JournalEvent($journal);
        $eventDispatcher->dispatch(BoardEvents::POST_DELETE, $event);
        if ($event->getResponse()) {
            return $event->getResponse();
        }
        $this->successFlashBag('successful.remove');
        return $this->redirectToRoute('ojs_journal_board_index', ['journalId' => $journal->getId()]);
    }