فهرست منبع

Fix bug when no related admin is defined

Thomas Rabaix 13 سال پیش
والد
کامیت
61747738c2
2فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 1 1
      Controller/HelperController.php
  2. 4 0
      Twig/Extension/SonataAdminExtension.php

+ 1 - 1
Controller/HelperController.php

@@ -134,7 +134,7 @@ class HelperController extends Controller
         }
 
         $description = 'no description available';
-        foreach (array('getTitle', 'getName', '__toString') as $method) {
+        foreach (array('getAdminTitle', 'getTitle', 'getName', '__toString') as $method) {
             if (method_exists($object, $method)) {
                 $description = $object->$method();
                 break;

+ 4 - 0
Twig/Extension/SonataAdminExtension.php

@@ -182,6 +182,10 @@ class SonataAdminExtension extends \Twig_Extension
     {
         $method = $fieldDescription->getOption('associated_tostring', '__toString');
 
+        if (!is_object($element)) {
+            return $element;
+        }
+
         if (!method_exists($element, $method)) {
             throw new \RunTimeException(sprintf('You must define an `associated_tostring` option or create a `%s::__toString` method to the field option %s from service %s is ', get_class($element), $fieldDescription->getName(), $fieldDescription->getAdmin()->getCode()));
         }