Skip to content

Instantly share code, notes, and snippets.

@gaetanhauray
Created August 8, 2017 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaetanhauray/ad5544129b5f60722298c15d6ef54452 to your computer and use it in GitHub Desktop.
Save gaetanhauray/ad5544129b5f60722298c15d6ef54452 to your computer and use it in GitHub Desktop.
{#
Je change la façon d'afficher l'élément du formulaire
fichier présent dans le dossier app
#}
{% extends 'bootstrap_3_layout.html.twig' %}
{% block choice_widget_expanded %}
test
{% endblock choice_widget_expanded %}
{#
J'affiche cet élément dans un twig
formElement correspond au champs ajouté au dessus
Fichier présent dans les templates du bundle
#}
{% form_theme form 'form/choice_checkbox.html.twig' %}
{{ form_widget(formElement) }}
/**
* Ajout du champs dans le formulaire, un ChoiceType, multiple, expanded et required
* Image du rendu du champs : https://pasteboard.co/GEGqWpi.png
**/
$constraints = array(
new NotBlank(array('message' => 'mandatory_field'))
);
$form->add(
'fieldValues',
ChoiceType::class,
array(
'placeholder' => 'project.form.select_a_option',
'attr' => array(
'class' => "form-control form-checkbox field-checkbox",
),
'choices' => array(
$projectFieldVO->getDefinition()->getFieldValues(),
),
'choice_label' => function ($fieldValue) {
/** @var FieldValueVO $fieldValue */
return ($fieldValue) ? $fieldValue->getValue() : null;
},
'choice_value' => function ($fieldValue) {
/** @var FieldValueVO $fieldValue */
if (!is_array($fieldValue)) {
return ($fieldValue) ? $fieldValue->getCle() : null;
}
else {
return $fieldValue[0]->getCle();
}
},
'group_by' => function ($fieldValue, $key, $index) {
return null;
},
'label' => $label,
'label_attr' => array(
'class' => 'control-label',
),
'multiple' => true,
'expanded' => true,
'required' => true,
'constraints' => $constraints
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment