Networking\InitCmsBundle\Controller\MediaAdminController::deleteAction PHP Method

deleteAction() public method

public deleteAction ( mixed $id ) : Response | RedirectResponse
$id mixed
return Symfony\Component\HttpFoundation\Response | Symfony\Component\HttpFoundation\RedirectResponse
    public function deleteAction($id)
    {
        $id = $this->get('request')->get($this->admin->getIdParameter());
        $object = $this->admin->getObject($id);
        if (!$object) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }
        if (false === $this->admin->isGranted('DELETE', $object)) {
            throw new AccessDeniedException();
        }
        /** @var Request $request */
        $request = $this->get('request_stack')->getCurrentRequest();
        if ($request->getMethod() == 'DELETE') {
            try {
                $this->admin->delete($object);
                $this->get('session')->getFlashBag()->add('sonata_flash_success', 'flash_delete_success');
            } catch (ModelManagerException $e) {
                $this->get('session')->getFlashBag()->add('sonata_flash_error', 'flash_delete_error');
            }
            return new RedirectResponse($this->admin->generateUrl('list', array('active_tab' => $this->get('request')->get('context'))));
        }
        return $this->render($this->admin->getTemplate('delete'), array('object' => $object, 'action' => 'delete'));
    }