symfony2admingenerator / AvocodeFormExtensionsBundle

(old-legacy) Symfony2 form extensions for Admingenerator project (also working standalone!)
Other
48 stars 31 forks source link

Field to be sorted #153

Open rpostolov opened 9 years ago

rpostolov commented 9 years ago

Hi,

I have a simple question, i search for the solution but i couldn't find an answer.

I have a field which is a list of countries, but its not sorted. I want to know if it's possible to add an sort option in the generator.yml and if it's yes how.

Here is a part of my admin-generator.yml file

fields:      
      country:
        label: Country
        addFormOptions:
         required: true

Thanks :)

sescandell commented 9 years ago

Hi @rpostolov

This issue should be created into the AdmingeneratorGeneratorBundle... But let's give you an answer there:

In your [Edit|New]FormType generated file, you can add/customize form options. I think so there you should write your own QueryBuilder. Something like this:

protected function getFormOption($name, array $formOptions)
    {
        if ('country' === $name) {
                $formOptions['query_builder'] = function (CountryRepository $countryRepository){
                    return $countryRepository->getFindQueryBuilderOrderedByName();
                };
            }
        }

        return $formOptions;
    }

By the way, do you know Symfony provides such a form (maybe out of your context): http://symfony.com/fr/doc/current/reference/forms/types/country.html

Hoping that helps,

rpostolov commented 9 years ago

Hi @sescandell,

Thank you for the answer, i will try this today.

Sorry, i thought that it's belong to Avocode, my bad.

Have a nice day !