diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index ec7420540..928f1de64 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -187,7 +187,7 @@ class CustomFieldChoice implements CustomFieldInterface * @param CustomField $customField * @return string html representation */ - public function render($value, CustomField $customField) + public function render($value, CustomField $customField, $documentType = 'html') { //extract the data. They are under a _choice key if they are stored with allow_other $data = (isset($value['_choices'])) ? $value['_choices'] : $value; @@ -198,8 +198,13 @@ class CustomFieldChoice implements CustomFieldInterface $choices[] = array('name' => $value['_other'], 'slug' => '_other'); } + $template = 'ChillCustomFieldsBundle:CustomFieldsRendering:choice.html.twig'; + if($documentType == 'csv') { + $template = 'ChillCustomFieldsBundle:CustomFieldsRendering:choice.csv.twig'; + } + return $this->templating - ->render('ChillCustomFieldsBundle:CustomFieldsRendering:choice.html.twig', + ->render($template, array( 'choices' => $choices, 'selected' => $selected, diff --git a/CustomFields/CustomFieldInterface.php b/CustomFields/CustomFieldInterface.php index 952d6af56..149e5500b 100644 --- a/CustomFields/CustomFieldInterface.php +++ b/CustomFields/CustomFieldInterface.php @@ -43,7 +43,7 @@ interface CustomFieldInterface * @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField * @return string an html representation of the value */ - public function render($value, CustomField $customField); + public function render($value, CustomField $customField, $documentType = 'html'); public function getName(); diff --git a/CustomFields/CustomFieldText.php b/CustomFields/CustomFieldText.php index 1b79366a8..a8d58ac72 100644 --- a/CustomFields/CustomFieldText.php +++ b/CustomFields/CustomFieldText.php @@ -90,7 +90,7 @@ class CustomFieldText implements CustomFieldInterface )); } - public function render($value, CustomField $customField) + public function render($value, CustomField $customField, $documentType = 'html') { return $this->templating ->render('ChillCustomFieldsBundle:CustomFieldsRendering:text.html.twig', array('text' => $value)); diff --git a/CustomFields/CustomFieldTitle.php b/CustomFields/CustomFieldTitle.php index 2c0ad9f7f..78b6f08d6 100644 --- a/CustomFields/CustomFieldTitle.php +++ b/CustomFields/CustomFieldTitle.php @@ -67,7 +67,7 @@ class CustomFieldTitle implements CustomFieldInterface )); } - public function render($value, CustomField $customField) + public function render($value, CustomField $customField, $documentType = 'html') { return $this->templating ->render('ChillCustomFieldsBundle:CustomFieldsRendering:title.html.twig', diff --git a/Resources/views/CustomFieldsRendering/choice.csv.twig b/Resources/views/CustomFieldsRendering/choice.csv.twig new file mode 100644 index 000000000..7c9c5ed1c --- /dev/null +++ b/Resources/views/CustomFieldsRendering/choice.csv.twig @@ -0,0 +1,13 @@ +{% if selected|length > 0 %} +{%- for choice in choices -%} + {% if choice['slug'] in selected %} + {%- if choice['slug'] is not same as('_other') -%} + {{ choice['name']|localize_translatable_string }} + {%- else -%} + {{ choice['name'] }} + {%- endif -%} + {% endif %} +{%- endfor -%} +{% else %} + {{ 'None'|trans }} +{% endif %} \ No newline at end of file diff --git a/Service/CustomFieldsHelper.php b/Service/CustomFieldsHelper.php index ae879e10b..5be4fbe24 100644 --- a/Service/CustomFieldsHelper.php +++ b/Service/CustomFieldsHelper.php @@ -113,14 +113,14 @@ class CustomFieldsHelper * @param string $slug the slug you want to render. The html is be safe. * @throws CustomFieldsHelperException if slug is missing */ - public function renderCustomField(array $fields, $classOrCustomField, $slug = null) + public function renderCustomField(array $fields, $classOrCustomField, $type='html', $slug = null) { $customField = ($classOrCustomField instanceof CustomField) ? $classOrCustomField : $this->getCustomField($classOrCustomField, $slug); $slug = $customField->getSlug(); $rawValue = (isset($fields[$slug])) ? $fields[$slug] : null; return $this->provider->getCustomFieldByType($customField->getType()) - ->render($rawValue, $customField); + ->render($rawValue, $customField, $type); } } \ No newline at end of file diff --git a/Templating/Twig/CustomFieldRenderingTwig.php b/Templating/Twig/CustomFieldRenderingTwig.php index 4244e978d..c4fc15ddf 100644 --- a/Templating/Twig/CustomFieldRenderingTwig.php +++ b/Templating/Twig/CustomFieldRenderingTwig.php @@ -100,10 +100,10 @@ class CustomFieldRenderingTwig extends \Twig_Extension implements ContainerAware * @param string $slug only necessary if the first argument is NOT a CustomField instance * @return string HTML representation of the custom field, as described in the CustomFieldInterface. Is HTML safe */ - public function renderWidget(array $fields, $customFieldOrClass, $slug = null) + public function renderWidget(array $fields, $customFieldOrClass, $documentType='html', $slug = null) { return $this->container->get('chill.custom_field.helper') - ->renderCustomField($fields, $customFieldOrClass, $slug); + ->renderCustomField($fields, $customFieldOrClass, $documentType, $slug); }