EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Choosen only parent category from select list

Open Pablossoo opened this issue 10 years ago • 11 comments

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.

Pablossoo avatar Aug 01 '16 12:08 Pablossoo

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

yun548 avatar Aug 03 '16 12:08 yun548

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

Pablossoo avatar Aug 04 '16 19:08 Pablossoo

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

yceruto avatar Aug 04 '16 20:08 yceruto

Maybe can help you https://github.com/javiereguiluz/EasyAdminBundle/issues/1145

yceruto avatar Aug 04 '16 20:08 yceruto

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

Pablossoo avatar Aug 06 '16 14:08 Pablossoo

https://github.com/javiereguiluz/EasyAdminBundle/issues/947#issuecomment-197395006

yceruto avatar Aug 07 '16 05:08 yceruto

Great, thanks!

Pablossoo avatar Aug 07 '16 13:08 Pablossoo

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\htdocs\framework-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 avatar Aug 09 '16 12:08 Pablossoo

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

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

yceruto avatar Aug 09 '16 13:08 yceruto

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

Pablossoo avatar Aug 09 '16 13:08 Pablossoo

Hello @yceruto, Can pass parameter?

eksahin avatar Nov 03 '16 11:11 eksahin