Easyadminbundle: Choosen only parent category from select list

Created on 1 Aug 2016  路  11Comments  路  Source: EasyCorp/EasyAdminBundle

Hello,

I have two entity.
Event and category. Relation n:1. One category can have many events. Now if I would like edit/add new event, in select list should show only parent category and not all like now.

http://pl.tinypic.com/r/2hp81as/9 should show only Fitness and CrossFitnes.

All 11 comments

Maybe I misunderstood, but isn't the purpose of the field to allow the admin to change the category ?

Yes, but there are subcategories and parent categories. The administrator should be able choose the parent categories at adding or edit events.

@Pablossoo you've tried the query_builder options to filter this choices ?

No i don't tried. Can you show me simple example?

Great, thanks!

I have one problem..

Type error: Argument 2 passed to JavierEguiluz\Bundle\EasyAdminBundle\Form\Type\Configurator\AutocompleteTypeConfigurator::supports() must be of the type array, string given, called in C:\xampp\htdocsframework-standard-edition\vendor\javiereguiluz\easyadmin-bundle\Form\Type\EasyAdminFormType.php on line 66

My YML

fields:
                     - 'title'
                     - {property: 'start', type: 'text'}
                     - {property: 'end', type: 'text'}
                     - 'allDay'
                     - {property: 'category', type_options:  query_builder: 'FitnesBundle\Repository\CategoryRepository::available'}
                     - 'user'
                     - 'max'


Repository
 public static function available(CategoryRepository $repository)
    {
        return $repository->createQueryBuilder('c')
            ->where("c.enabled IS TRUE")
            ->orderBy('c.name');
    }

where is problem ?

@Pablossoo fix that (missing { ... }):

- { property: 'category', type_options: { query_builder: 'FitnesBundle\Repository\CategoryRepository::available' } }

Thank you! but why this not described in guide? this is very helpful.

Hello @yceruto,
Can pass parameter?

Was this page helpful?
0 / 5 - 0 ratings