mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-18 08:14:24 +00:00
allowing csv rendering for custom fields
This commit is contained in:
parent
77247de990
commit
47a9a29236
@ -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,
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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',
|
||||
|
13
Resources/views/CustomFieldsRendering/choice.csv.twig
Normal file
13
Resources/views/CustomFieldsRendering/choice.csv.twig
Normal file
@ -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 %}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user