简体   繁体   中英

SonataAdmin - sonata_type_choice_field_mask

    ->add('billManagement', 'sonata_type_choice_field_mask', array(
    'choices' => array(
        'FI' => 'FI',
        'GI' => 'GI'
    ),
    'map' => array(
        'FI' => array('company'),
        'GI' => array('company')
    ),
    'empty_value' => 'Mode de financement',
    'required' => true
))
->add('company')
->end()

I show here a list box with choices such as "GI" or "FI". Depending on the choice, another box list is displayed. A box Companies list. But always depending on the choice, the list of companies to be filtered. I would like to see a company whose query field changes depending on the choice of billManagement, "FI" or "GI".

I tried that but it does not work

    ->add('billManagement', 'sonata_type_choice_field_mask', array(
    'choices' => array(
        'FI' => 'FI',
        'GI' => 'GI'
    ),
    'map' => array(
        'FI' => $formMapper->add('company', 'sonata_type_model', array(
            'class' => 'AppBundle\Entity\User\Company',
            'query' => $companyFinance
        )),
        'GI' => $formMapper->add('company', 'sonata_type_model', array(
            'class' => 'AppBundle\Entity\User\Company',
            'query' => $company
        )),
    ),
    'empty_value' => 'Mode de financement',
    'required' => true
))
->end()

I have achieved what I wanted to do. I just add two fields not mapped

    ->add('billManagement', 'sonata_type_choice_field_mask', array(
    'choices' => array(
        'FI' => 'FI',
        'GI' => 'GI'
    ),
    'map' => array(
        'FI' => array('companyFinance'),
        'GI' => array('company'),
),
    'empty_value' => 'Mode de financement',
    'required' => true
))
->add('companyFinance', 'sonata_type_model', array(
    'class' => 'AppBundle\Entity\User\Company',
    'query' => $companyFinance,
    'mapped' => false
))
->add('company', 'sonata_type_model', array(
    'class' => 'AppBundle\Entity\User\Company',
    'query' => $company,
    'mapped' => false
))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM