Created
August 8, 2017 10:20
-
-
Save gaetanhauray/ad5544129b5f60722298c15d6ef54452 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
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) }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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