コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function deleteAction($id)
 {
     if (!$this->_canUserBeDeleted($id)) {
         return $this->redirect($this->admin->generateUrl('edit', array('id' => $id)));
     }
     return parent::deleteAction($id);
 }
コード例 #2
0
 public function deleteAction($id)
 {
     /** @var $action RedirectResponse */
     $action = parent::deleteAction($id);
     if ($this->getRequest()->getMethod() == 'DELETE' && $this->isXmlHttpRequest()) {
         return $this->renderJson(array('result' => 'ok'));
     }
     return $action;
 }
コード例 #3
0
 public function deleteAction($id)
 {
     if ($this->getRestMethod() == 'DELETE') {
         /** @var SeoFile $seo_file */
         $seo_file = $this->admin->getObject($id);
         $this->deleteFile($seo_file->getName());
     }
     return parent::deleteAction($id);
 }
コード例 #4
0
 /**
  * Deletes form
  *
  * @param int|null|string $id
  * @param Request $request
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function deleteAction($id, Request $request = null)
 {
     if ($this->getRestMethod() == 'DELETE') {
         /** @var FcForm $object */
         $fc_form = $this->admin->getObject($id);
         if ($fc_form->isUsedAsWidget()) {
             $this->addFlash('sonata_flash_error', $this->admin->trans('fc.message.admin.form.is_used_as_widget', array(), 'FenrizbesFormConstructorBundle'));
             return $this->redirectTo($fc_form);
         }
     }
     return parent::deleteAction($id);
 }
コード例 #5
0
 public function testDeleteActionInvalidCsrfToken()
 {
     $object = new \stdClass();
     $this->admin->expects($this->once())->method('getObject')->will($this->returnValue($object));
     $this->admin->expects($this->once())->method('isGranted')->with($this->equalTo('DELETE'))->will($this->returnValue(true));
     $this->request->setMethod('POST');
     $this->request->request->set('_method', 'DELETE');
     $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
     try {
         $this->controller->deleteAction(1);
     } catch (HttpException $e) {
         $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
         $this->assertSame(400, $e->getStatusCode());
     }
 }
コード例 #6
0
 public function testDeleteActionError()
 {
     $object = new \stdClass();
     $this->admin->expects($this->once())->method('getObject')->will($this->returnValue($object));
     $this->admin->expects($this->once())->method('isGranted')->with($this->equalTo('DELETE'))->will($this->returnValue(true));
     $this->expectTranslate('flash_delete_error');
     $this->admin->expects($this->once())->method('delete')->will($this->returnCallback(function () {
         throw new ModelManagerException();
     }));
     $this->request->setMethod('DELETE');
     $response = $this->controller->deleteAction(1);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     $this->assertSame(array('flash_delete_error'), $this->session->getFlashBag()->get('sonata_flash_error'));
     $this->assertEquals('list', $response->getTargetUrl());
 }
コード例 #7
0
 public function deleteAction($id)
 {
     Request::enableHttpMethodParameterOverride();
     // <-- add this line
     return parent::deleteAction($id);
 }