mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Merge branch 'master' of git://github.com/Chill-project/CustomFields
This commit is contained in:
commit
ecd919adea
@ -28,6 +28,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Chill\CustomFieldsBundle\Form\Type\ChoicesListType;
|
||||
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
|
||||
use Chill\CustomFieldsBundle\Form\Type\ChoiceWithOtherType;
|
||||
use Symfony\Bridge\Twig\TwigEngine;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -49,10 +50,17 @@ class CustomFieldChoice implements CustomFieldInterface
|
||||
|
||||
private $defaultLocale;
|
||||
|
||||
public function __construct(RequestStack $requestStack, $defaultLocale)
|
||||
/**
|
||||
*
|
||||
* @var TwigEngine
|
||||
*/
|
||||
private $templating;
|
||||
|
||||
public function __construct(RequestStack $requestStack, $defaultLocale, TwigEngine $templating)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
$this->defaultLocale = $defaultLocale;
|
||||
$this->templating = $templating;
|
||||
}
|
||||
|
||||
|
||||
@ -146,7 +154,27 @@ class CustomFieldChoice implements CustomFieldInterface
|
||||
|
||||
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;
|
||||
|
||||
$selected = (is_array($data)) ? $data : array($data);
|
||||
|
||||
$choices = $customField->getOptions()[self::CHOICES];
|
||||
|
||||
if (in_array('_other', $selected)){
|
||||
$choices[] = array('name' => $value['_other'], 'slug' => '_other');
|
||||
}
|
||||
|
||||
return $this->templating
|
||||
->render('ChillCustomFieldsBundle:CustomFieldsRendering:choice.html.twig',
|
||||
array(
|
||||
'choices' => $choices,
|
||||
'selected' => $selected,
|
||||
'multiple' => $customField->getOptions()[self::MULTIPLE],
|
||||
'expanded' => $customField->getOptions()[self::EXPANDED],
|
||||
'locale' => $this->defaultLocale
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function serialize($value, CustomField $customField)
|
||||
|
@ -48,6 +48,7 @@ services:
|
||||
arguments:
|
||||
- "@request_stack"
|
||||
- %locale%
|
||||
- "@templating"
|
||||
tags:
|
||||
- { name: 'chill.custom_field', type: 'choice' }
|
||||
|
||||
|
19
Resources/views/CustomFieldsRendering/choice.html.twig
Normal file
19
Resources/views/CustomFieldsRendering/choice.html.twig
Normal file
@ -0,0 +1,19 @@
|
||||
<ul class="custom_fields choice">
|
||||
{%- for choice in choices -%}
|
||||
{% if choice['slug'] in selected %}{%- set is_selected = true -%}{%- else -%}{%- set is_selected = false -%}{%- endif -%}
|
||||
{# {%- if choice['slug'] in selected -%} #}
|
||||
<li class="{% if true %} selected {% endif %}">
|
||||
{%- if multiple -%}
|
||||
<input type="checkbox" {% if is_selected %}checked{% endif %} />
|
||||
{%- else -%}
|
||||
<input type="radio" {% if is_selected %}checked{% endif %} />
|
||||
{%- endif -%}
|
||||
{%- if choice['slug'] is not same as('_other') -%}
|
||||
{{ choice['name'][app.request.locale]|default(choice['name'][locale]|default('Not available in your language'|trans)) }}
|
||||
{%- else -%}
|
||||
<span class="other">{{ 'Other value'|trans }} :</span> {{ choice['name'] }}
|
||||
{%- endif -%}
|
||||
</li>
|
||||
{# {%- endif -%} #}
|
||||
{%- endfor -%}
|
||||
</ul>
|
Loading…
x
Reference in New Issue
Block a user