Created
July 12, 2018 13:27
-
-
Save Kim-Vallee/d76209742397a1307032ca19edde0b11 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
<?php | |
namespace App\Form; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
use App\Form\Type\FormuleChoiceType; | |
class EntrepriseSignupType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('formule', FormuleChoiceType::class) | |
; | |
} | |
} |
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
<?php | |
namespace App\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
class FormuleChoiceType extends AbstractType | |
{ | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefaults(array( | |
"choices" => array( | |
"Radin" => 1, | |
"Pas riche" => 2, | |
"Engagé" => 3, | |
"Crésus" => 4, | |
), | |
"multiple" => false, | |
"expanded" => true, | |
)); | |
} | |
public function getParent() | |
{ | |
return ChoiceType::class; | |
} | |
} |
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
{% extends 'base.html.twig' %} | |
{% block formulechoice_widget %} | |
{% spaceless %} | |
{% if expanded %} | |
<div {{ block('widget_container_attributes') }}> | |
{% for child in form %} | |
{{ form_widget(child) }} | |
<h1>Coucou</h1> | |
{{ form_label(child) }} | |
{% endfor %} | |
</div> | |
{% else %} | |
{# just let the choice widget render the select tag #} | |
{{ block('choice_widget') }} | |
{% endif %} | |
{% endspaceless %} | |
{% endblock %} | |
{% block body %} | |
{{ form_start(form) }} | |
{{ form_label(form.formule) }} | |
{{ form_errors(form.formule) }} | |
{{ form_widget(form.formule, {'attr': {'class' : 'd-flex justify-content-around'}}) }} | |
{{ form_help(form.formule) }} | |
{{ form_end(form) }} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment