Преглед на файлове

added choice type to list and show

Tiago Garcia преди 11 години
родител
ревизия
82cb1640e9
променени са 4 файла, в които са добавени 55 реда и са изтрити 0 реда
  1. 23 0
      Resources/views/CRUD/list_choice.html.twig
  2. 27 0
      Resources/views/CRUD/show_choice.html.twig
  3. 4 0
      Tests/Twig/Extension/SonataAdminExtensionTest.php
  4. 1 0
      composer.json

+ 23 - 0
Resources/views/CRUD/list_choice.html.twig

@@ -0,0 +1,23 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% extends admin.getTemplate('base_list_field') %}
+
+{% block field %}
+    {% if field_description.options.choices and value in field_description.options.choices|keys %}
+        {% if field_description.options.catalogue is not defined %}
+            {% set value = field_description.options.choices[value] %}
+        {% else %}
+            {% set value = field_description.options.choices[value]|trans({}, field_description.options.catalogue) %}
+        {% endif %}
+    {% endif %}
+    {{ parent() }}
+{% endblock %}

+ 27 - 0
Resources/views/CRUD/show_choice.html.twig

@@ -0,0 +1,27 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
+
+{% block field%}
+    {% if field_description.options.choices and value in field_description.options.choices|keys %}
+        {% if field_description.options.catalogue is not defined %}
+            {% set value = field_description.options.choices[value] %}
+        {% else %}
+            {% set value = field_description.options.choices[value]|trans({}, field_description.options.catalogue) %}
+        {% endif %}
+    {% endif %}
+
+    {% if field_description.options.safe %}
+        {{ value|raw }}
+    {% else %}
+        {{ value }}
+    {% endif %}
+{% endblock %}

+ 4 - 0
Tests/Twig/Extension/SonataAdminExtensionTest.php

@@ -198,6 +198,8 @@ class SonataAdminExtensionTest extends \PHPUnit_Framework_TestCase
                         return 'SonataAdminBundle:CRUD:list_currency.html.twig';
                     case 'percent':
                         return 'SonataAdminBundle:CRUD:list_percent.html.twig';
+                    case 'choice':
+                        return 'SonataAdminBundle:CRUD:list_choice.html.twig';
                     case 'array':
                         return 'SonataAdminBundle:CRUD:list_array.html.twig';
                     case 'trans':
@@ -300,6 +302,8 @@ class SonataAdminExtensionTest extends \PHPUnit_Framework_TestCase
                         return 'SonataAdminBundle:CRUD:show_currency.html.twig';
                     case 'percent':
                         return 'SonataAdminBundle:CRUD:show_percent.html.twig';
+                    case 'choice':
+                        return 'SonataAdminBundle:CRUD:show_choice.html.twig';
                     case 'array':
                         return 'SonataAdminBundle:CRUD:show_array.html.twig';
                     case 'trans':

+ 1 - 0
composer.json

@@ -37,6 +37,7 @@
     },
     "require-dev": {
         "jms/translation-bundle": "*@dev",
+        "symfony/yaml": "~2.2",
         "sonata-project/intl-bundle": "~2.1"
     },
     "suggest": {