<commit_before><?php

namespace CrewCallBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;

use CrewCallBundle\Lib\ExternalEntityConfig;
use CrewCallBundle\Form\AddressType;

class PersonType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('first_name')
            ->add('last_name')
            ->add('date_of_birth', BirthdayType::class, array('required' => false))
            ->add('diets', ChoiceType::class,array(
                'choices' => ExternalEntityConfig::getTypesAsChoicesFor('Person', 'Diet'),
                'expanded'  => true,
                'multiple'  => true,))
            ->add('mobile_phone_number')
            ->add('home_phone_number')
            ->add('state', ChoiceType::class, array('choices' => ExternalEntityConfig::getStatesAsChoicesFor('Person')))
            ->add('system_role', ChoiceType::class,
                array(
                    'expanded'  => true,
                    'multiple' =>  false,
                    'choices' => ExternalEntityConfig::getSystemRolesAsChoices(),
                    'preferred_choices' => 'ROLE_USER'
                )
            )
            // ->add('attributes')
            ->add('address', AddressType::class, ['address_elements' => $options['address_elements']])
            ->add('postal_address', AddressType::class, ['address_elements' => $options['address_elements']])
            ;
    }
    
    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'CrewCallBundle\Entity\Person',
            'address_elements' => []
        ));
    }

    public function getParent()
    {
        return 'FOS\UserBundle\Form\Type\RegistrationFormType';

        // Or for Symfony < 2.8
        // return 'fos_user_registration';
    }

    /**<commit_msg>Just revert to the annoying way to handle system roles<commit_after><?php

namespace CrewCallBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;

use CrewCallBundle\Lib\ExternalEntityConfig;
use CrewCallBundle\Form\AddressType;

class PersonType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('first_name')
            ->add('last_name')
            ->add('date_of_birth', BirthdayType::class, array('required' => false))
            ->add('diets', ChoiceType::class,array(
                'choices' => ExternalEntityConfig::getTypesAsChoicesFor('Person', 'Diet'),
                'expanded'  => true,
                'multiple'  => true,))
            ->add('mobile_phone_number')
            ->add('home_phone_number')
            ->add('state', ChoiceType::class, array('choices' => ExternalEntityConfig::getStatesAsChoicesFor('Person')))

/* Not really working. TODO: Try again.
            ->add('system_role', ChoiceType::class,
                array(
                    'expanded'  => true,
                    'multiple' =>  false,
                    'choices' => ExternalEntityConfig::getSystemRolesAsChoices(),
                    'preferred_choices' => 'ROLE_USER'
                )
            )
*/
           ->add('roles', ChoiceType::class,
                array(
                    'multiple' =>  true,
                    'choices' =>
                        array(
                            'User able to use this application (Crewmember)' => 'ROLE_USER',
                            'Admin user' => 'ROLE_ADMIN',
                            'Person with roles' => 'ROLE_PERSON'
                            )
                )
            )
            ->add('address', AddressType::class, ['address_elements' => $options['address_elements']])
            ->add('postal_address', AddressType::class, ['address_elements' => $options['address_elements']])
            ;
    }
    
    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'CrewCallBundle\Entity\Person',
            'address_elements' => []
        ));
    }

    public function getParent()
    {
        return 'FOS\UserBundle\Form\Type\RegistrationFormType';

        // Or for Symfony < 2.8
        // return 'fos_user_registration';
    }

    /**
{'fraction_non_alphanumeric': 0.1319796954314721, 'fraction_numerical': 0.0008121827411167512, 'mean_word_length': 2.1276190476190475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6394076', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1322, 'n_words': 216}