Sonataadminbundle: Form themes defined in getFilterTheme are ignored

Created on 28 Jun 2016  路  8Comments  路  Source: sonata-project/SonataAdminBundle

Environment

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle              3.3.2 The missing Symfony Admin Generator
sonata-project/block-bundle              3.0.1 Symfony SonataBlockBundle
sonata-project/cache                     1.0.7 Cache library
sonata-project/core-bundle               3.0.3 Symfony SonataCoreBundle
sonata-project/doctrine-orm-admin-bundle 3.0.4 Symfony Sonata / Integrate Doctrine ORM into...
sonata-project/exporter                  1.5.0 Lightweight Exporter library

Subject

SonataAdminBundle:CRUD:base_list.html.twig list_filters block overwrites (line 226) the filter theme set in CRUDController:108

Steps to reproduce

  1. Add any custom form theme to the datagrid filters through an Admin class. e.g.:

    public function getFilterTheme() {
         return array_merge(parent::getFilterTheme(), [
              'SonataCoreBundle:Form:datepicker.html.twig'
         ]);
    }
    
  2. Try to use a form type which theme is defined in the custom form theme.

    Expected results

Form rendered correctly

expected

Actual results

Custom form theme ignored. Form is rendered with default theme.

actual

bug pending author stale

Most helpful comment

I added the screenshots to the PR header

All 8 comments

Thanks for the report @fracsi.

Does it happen only for filters?

@Soullivaneuh Yes it only affects filters.

could add some screenshots?

And the Admin class with the corresponding used field please.

@OskarStark @Soullivaneuh

I wanted to use date_range filter with datepicker, so in the admin:

$datagridMapper
    ->add('date', 'doctrine_orm_date_range', [
        'label' => 'Date',
        'field_type' => 'sonata_type_date_range_picker',
            'field_options' => [
                'field_options_start' => [
                    'label' => 'Date start'
                ],
                'field_options_end' => [
                    'label' => 'Date end'
                ]
            ]
        ]);

And:

public function getFilterTheme()
{
    return array_merge(parent::getFilterTheme(), [
        'SonataCoreBundle:Form:datepicker.html.twig'
    ]);
}

Actual result:
actual

Expected result:
expected

Bug confirmed.

Indeed, removing this line solve the issue: https://github.com/sonata-project/SonataAdminBundle/blob/3.3.2/Resources/views/CRUD/base_list.html.twig#L226

This line seems to be introduced a long time ago in https://github.com/sonata-project/SonataAdminBundle/commit/2d4b2311ef47f24a7b0c3c52856554ec44f3f0c6 by @Bladrak and modified in #2061 by @boajer.

Could you please guys give us some hints?

This can be done with configuration:

sonata_admin:
    templates:
        filter: SonataCoreBundle:Form:datepicker.html.twig

But this limits the choice to one template, not an array.

BTW, why putting this with configuration when this can be done with the Admin class?

I added the screenshots to the PR header

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings