瀏覽代碼

Merge branch '2.1'

Thomas Rabaix 12 年之前
父節點
當前提交
e98108d9bf

+ 11 - 0
Controller/CRUDController.php

@@ -214,8 +214,19 @@ class CRUDController extends Controller
         if ($this->getRequest()->getMethod() == 'DELETE') {
         if ($this->getRequest()->getMethod() == 'DELETE') {
             try {
             try {
                 $this->admin->delete($object);
                 $this->admin->delete($object);
+
+                if ($this->isXmlHttpRequest()) {
+                    return $this->renderJson(array('result' => 'ok'));
+                }
+
                 $this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
                 $this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
+
             } catch (ModelManagerException $e) {
             } catch (ModelManagerException $e) {
+
+                if ($this->isXmlHttpRequest()) {
+                    return $this->renderJson(array('result' => 'error'));
+                }
+
                 $this->get('session')->setFlash('sonata_flash_error', 'flash_delete_error');
                 $this->get('session')->setFlash('sonata_flash_error', 'flash_delete_error');
             }
             }
 
 

+ 1 - 1
Resources/config/core.xml

@@ -40,8 +40,8 @@
         <!-- Translation extractor -->
         <!-- Translation extractor -->
         <service id="sonata.admin.translator.extractor.jms_translator_bundle" class="Sonata\AdminBundle\Translator\Extractor\JMSTranslatorBundle\AdminExtractor" >
         <service id="sonata.admin.translator.extractor.jms_translator_bundle" class="Sonata\AdminBundle\Translator\Extractor\JMSTranslatorBundle\AdminExtractor" >
             <tag name="jms_translation.extractor" alias="sonata_admin"/>
             <tag name="jms_translation.extractor" alias="sonata_admin"/>
-            <argument type="service" id="logger" />
             <argument type="service" id="sonata.admin.pool" />
             <argument type="service" id="sonata.admin.pool" />
+            <argument type="service" id="logger" on-invalid="ignore" />
         </service>
         </service>
 
 
         <!-- controller as services -->
         <!-- controller as services -->

+ 8 - 4
Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php

@@ -25,10 +25,10 @@ class AdminExtractor implements ExtractorInterface, TranslatorInterface, Securit
     private $domain;
     private $domain;
 
 
     /**
     /**
-     * @param \Symfony\Component\HttpKernel\Log\LoggerInterface $logger
      * @param \Sonata\AdminBundle\Admin\Pool                    $adminPool
      * @param \Sonata\AdminBundle\Admin\Pool                    $adminPool
+     * @param \Symfony\Component\HttpKernel\Log\LoggerInterface $logger
      */
      */
-    public function __construct(LoggerInterface $logger, Pool $adminPool)
+    public function __construct(Pool $adminPool, LoggerInterface $logger = null)
     {
     {
         $this->logger    = $logger;
         $this->logger    = $logger;
         $this->adminPool = $adminPool;
         $this->adminPool = $adminPool;
@@ -91,14 +91,18 @@ class AdminExtractor implements ExtractorInterface, TranslatorInterface, Securit
                 )
                 )
             );
             );
 
 
-            $this->logger->info(sprintf('Retrieving message from admin:%s - class: %s', $admin->getCode(), get_class($admin)));
+            if ($this->logger) {
+                $this->logger->info(sprintf('Retrieving message from admin:%s - class: %s', $admin->getCode(), get_class($admin)));
+            }
 
 
             foreach ($methods as $method => $calls) {
             foreach ($methods as $method => $calls) {
                 foreach ($calls as $args) {
                 foreach ($calls as $args) {
                     try {
                     try {
                         call_user_func_array(array($admin, $method), $args);
                         call_user_func_array(array($admin, $method), $args);
                     } catch (\Exception $e) {
                     } catch (\Exception $e) {
-                        $this->logger->err(sprintf('ERROR : admin:%s - Raise an exception : %s', $admin->getCode(), $e->getMessage()));
+                        if ($this->logger) {
+                            $this->logger->err(sprintf('ERROR : admin:%s - Raise an exception : %s', $admin->getCode(), $e->getMessage()));
+                        }
 
 
                         throw $e;
                         throw $e;
                     }
                     }