瀏覽代碼

Fix bug in getTemplate method

Andrej Hudec 12 年之前
父節點
當前提交
d99ad4b5dc
共有 1 個文件被更改,包括 5 次插入6 次删除
  1. 5 6
      Twig/Extension/SonataAdminExtension.php

+ 5 - 6
Twig/Extension/SonataAdminExtension.php

@@ -76,19 +76,18 @@ class SonataAdminExtension extends \Twig_Extension
 
     /**
      * @param FieldDescriptionInterface $fieldDescription
+     * @param string                    $defaultTemplate
      *
      * @return \Twig_TemplateInterface
      */
-    protected function getTemplate(FieldDescriptionInterface $fieldDescription)
+    protected function getTemplate(FieldDescriptionInterface $fieldDescription, $defaultTemplate)
     {
-        $default = $fieldDescription->getAdmin()->getTemplate('base_list_field');
-
-        $templateName = $fieldDescription->getTemplate() ? : $default;
+        $templateName = $fieldDescription->getTemplate() ? : $defaultTemplate;
 
         try {
             $template = $this->environment->loadTemplate($templateName);
         } catch (\Twig_Error_Loader $e) {
-            $template = $this->environment->loadTemplate($default);
+            $template = $this->environment->loadTemplate($defaultTemplate);
         }
 
         return $template;
@@ -105,7 +104,7 @@ class SonataAdminExtension extends \Twig_Extension
      */
     public function renderListElement($object, FieldDescriptionInterface $fieldDescription, $params = array())
     {
-        $template = $this->getTemplate($fieldDescription);
+        $template = $this->getTemplate($fieldDescription, $fieldDescription->getAdmin()->getTemplate('base_list_field'));
 
         return $this->output($fieldDescription, $template, array_merge($params, array(
             'admin'             => $fieldDescription->getAdmin(),