src/Kunstmaan/AdminListBundle/Controller/AdminListController.php
protected function doDeleteAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request)
    {
        /* @var $em EntityManager */
        $em = $this->getEntityManager();
        $helper = $em->getRepository($configurator->getRepositoryName())->findOneById($entityId);
        if ($helper === null) {
            throw new NotFoundHttpException('Entity not found.');
        }
        if (!$configurator->canDelete($helper)) {
            throw $this->createAccessDeniedException('You do not have sufficient rights to access this page.');
        }

        $indexUrl = $configurator->getIndexUrl();
        if ($request->isMethod('POST')) {
            $adminListEvent = new AdminListEvent($helper, $request);
            $this->container->get('event_dispatcher')->dispatch(
                AdminListEvents::PRE_DELETE,
                $adminListEvent
            );

            // Check if Response is given
            if ($adminListEvent->getResponse() instanceof Response) {
                return $adminListEvent->getResponse();
            }

            $em->remove($helper);
            $em->flush();
            $this->container->get('event_dispatcher')->dispatch(
                AdminListEvents::POST_DELETE,
                $adminListEvent
            );

            // Check if Response is given
            if ($adminListEvent->getResponse() instanceof Response) {
                return $adminListEvent->getResponse();
            }
        }

        return new RedirectResponse(
            $this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array())
        );
    }
protected function doDeleteAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request)
    {
        /* @var $em EntityManager */
        $em = $this->getEntityManager();
        $helper = $em->getRepository($configurator->getRepositoryName())->findOneById($entityId);
        if ($helper === null) {
            throw new NotFoundHttpException('Entity not found.');
        }
        if (!$configurator->canDelete($helper)) {
            throw $this->createAccessDeniedException('You do not have sufficient rights to access this page.');
        }

        $indexUrl = $configurator->getIndexUrl();
        if ($request->isMethod('POST')) {
            $adminListEvent = new AdminListEvent($helper, $request);
            $this->container->get('event_dispatcher')->dispatch(
                AdminListEvents::PRE_DELETE,
                $adminListEvent
            );

            // Check if Response is given
            if ($adminListEvent->getResponse() instanceof Response) {
                return $adminListEvent->getResponse();
            }

            $em->remove($helper);
            $em->flush();
            $this->container->get('event_dispatcher')->dispatch(
                AdminListEvents::POST_DELETE,
                $adminListEvent
            );

            // Check if Response is given
            if ($adminListEvent->getResponse() instanceof Response) {
                return $adminListEvent->getResponse();
            }
        }

        return new RedirectResponse(
            $this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array())
        );
    }
protected function doDeleteAction ( AbstractAdminListConfigurator $ configurator , $ entityId , Request $ request ) { /* @var $em EntityManager */ $ em = $ this -> getEntityManager ( ) ; $ helper = $ em -> getRepository ( $ configurator -> getRepositoryName ( ) ) -> findOneById ( $ entityId ) ; if ( $ helper === null ) { throw new NotFoundHttpException ( 'Entity not found.' ) ; } if ( ! $ configurator -> canDelete ( $ helper ) ) { throw $ this -> createAccessDeniedException ( 'You do not have sufficient rights to access this page.' ) ; } $ indexUrl = $ configurator -> getIndexUrl ( ) ; if ( $ request -> isMethod ( 'POST' ) ) { $ adminListEvent = new AdminListEvent ( $ helper , $ request ) ; $ this -> container -> get ( 'event_dispatcher' ) -> dispatch ( AdminListEvents :: PRE_DELETE , $ adminListEvent ) ; // Check if Response is given if ( $ adminListEvent -> getResponse ( ) instanceof Response ) { return $ adminListEvent -> getResponse ( ) ; } $ em -> remove ( $ helper ) ; $ em -> flush ( ) ; $ this -> container -> get ( 'event_dispatcher' ) -> dispatch ( AdminListEvents :: POST_DELETE , $ adminListEvent ) ; // Check if Response is given if ( $ adminListEvent -> getResponse ( ) instanceof Response ) { return $ adminListEvent -> getResponse ( ) ; } } return new RedirectResponse ( $ this -> generateUrl ( $ indexUrl [ 'path' ] , isset ( $ indexUrl [ 'params' ] ) ? $ indexUrl [ 'params' ] : array ( ) ) ) ; }
Delete the Entity using its ID

@param AbstractAdminListConfigurator $configurator The adminlist configurator
@param int                           $entityId     The id to delete
@param null|Request                  $request

@throws NotFoundHttpException
@throws AccessDeniedHttpException

@return Response
Delete the Entity using its ID