From b687e9e07dc209e95068dd375ce69091ddca4ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 20 Nov 2014 17:35:16 +0100 Subject: [PATCH] Add a 'none' text on rendering when the custom fields is empty close #347 --- CustomFields/CustomFieldChoice.php | 10 +++++++++- Resources/views/CustomFieldsRendering/choice.html.twig | 6 +++++- Resources/views/CustomFieldsRendering/text.html.twig | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index 907b44817..af030f1da 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -158,10 +158,18 @@ class CustomFieldChoice implements CustomFieldInterface return 'Choices'; } + /** + * + * @internal this function is able to receive data whichever is the value of "other", "multiple" + * @param mixed $value + * @param CustomField $customField + * @return string html representation + */ public function render($value, CustomField $customField) { //extract the data. They are under a _choice key if they are stored with allow_other - $data = (isset($value['_choices'])) ? $value['_choices'] : $value; + $data = (isset($value['_choices'])) ? $value['_choices'] : + is_null($value) ? array() : $value; $selected = (is_array($data)) ? $data : array($data); diff --git a/Resources/views/CustomFieldsRendering/choice.html.twig b/Resources/views/CustomFieldsRendering/choice.html.twig index 5bdd18bbd..937897d94 100644 --- a/Resources/views/CustomFieldsRendering/choice.html.twig +++ b/Resources/views/CustomFieldsRendering/choice.html.twig @@ -1,3 +1,4 @@ +{% if selected|length > 0 %} \ No newline at end of file + +{% else %} +
{{ 'None'|trans }}
+{% endif %} \ No newline at end of file diff --git a/Resources/views/CustomFieldsRendering/text.html.twig b/Resources/views/CustomFieldsRendering/text.html.twig index 9b2b76cb3..29db40680 100644 --- a/Resources/views/CustomFieldsRendering/text.html.twig +++ b/Resources/views/CustomFieldsRendering/text.html.twig @@ -1 +1 @@ -{{ text }} \ No newline at end of file +{% if text is not empty %}{{ text }}{% else %}{{ 'None'|trans }}{% endif %} \ No newline at end of file