Closed axzx closed 3 years ago
I never used it, but I would say that filter theme is for customType.
In order to have a datepicker you should juste use a DatePickerType
->add('date', DateRangeFilter::class, [], null, [
'required' => false,
'attr' => ['class' => 'sonata-datepicker'],
'field_type' => DateTimePickerType::class,
'field_options' => ['widget' => 'single_text', 'format' => 'dd/MM/yyyy'],
])
@VincentLanglet that's how I got it, but in order for the datepicker to appear it should be added in the twig configuration:
twig:
form_themes:
- '@SonataForm/Form/datepicker.html.twig'
it doesn't matter if the custom field or not, it would be nice to set this in getFilterTheme
Indeed I have added this in twig.form_themes
a long time ago (and forgot).
It was documented when it was in the CoreBundle
https://sonata-project.org/bundles/core/3-x/doc/reference/form_types.html#datepickertype-datetimepickertype
But there is no documentation for form-extension
https://github.com/sonata-project/form-extensions/issues/84.
(cc @sonata-project/contributors How does we fix this ?)
@axzx I never used getFilterTheme
but the getFormTheme
works for me with some custom type.
Did you try to add a DatePickerType in the editFields and add the datepicker
theme to the getFormTheme
?
@VincentLanglet I would just like to know what getFilter Theme is for. It would be nice if it worked the same way as getFormTheme. In my BaseAdmin I have
public function getFormTheme(): array
{
$themes = parent::getFormTheme();
$themes[] = 'Form/admin_form_fields.html.twig';
$themes[] = '@SonataForm/Form/datepicker.html.twig';
return $themes;
}
public function getFilterTheme(): array
{
$themes = parent::getFilterTheme();
$themes[] = '@SonataForm/Form/datepicker.html.twig';
return $themes;
}
and getFormTheme works fine.
IMHO getFilterTheme
is supposed to works the same way than getFormTheme
, and the code is similar.
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Controller/CRUDController.php#L138
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Controller/CRUDController.php#L378
That's why I wanted to check that '@SonataForm/Form/datepicker.html.twig'
was working for getFormTheme
.
I currently have no idea why it's not working for getFilterTheme
...
I guess it gets overriden by https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/base_list.html.twig#L266.
About those methods, the idea was to remove them.
ok, I try set like this:
sonata_admin:
templates:
filter: ['@SonataAdmin/Form/filter_admin_fields.html.twig', '@SonataForm/Form/datepicker.html.twig']
and I have an error:
Invalid type for path "sonata_admin.templates.filter". Expected scalar, but got array.
it turns out that it is not possible to set several filter form views in this way
About those methods, the idea was to remove them.
We still should fix it until it's removed.
Do you want to try a PR @axzx ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Environment
Sonata packages
Symfony packages
PHP version
Subject
I used
getFilterTheme
in the same way asgetFormTheme
and I expected changes in filters - enable date picker, but it doesn't give any results.Steps to reproduce
In admin class:
Expected results
Actual results