'Sonata admin send model_manager to custom field ModelAutocompleteType
Hello i am using symfony 5.4 with sonata admin. I created custom AppModelAutocopleteType
class AppModelAutocompleteType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'callback' => static function (AdminInterface $admin, array $property, $value) {
AutocompleteForIntegerAndString::execute($admin, $property, $value);
},
'to_string_callback' => function($entity, $property) {
return $entity->getLabel();
},
'minimum_input_length' => 1,
'delay' => 333,
]);
}
public function getParent()
{
return ModelAutocompleteType::class;
}
}
and in sonata admin class (Lead entity) in filter section i add this (networkProvider is relation to Lead entity)
->add('networkProvider', ModelFilter::class, [
'field_type' => AppModelAutocompleteType::class,
'field_options' => [
'property' => ['code', 'name'],
'class' => Lead::class,
'model_manager' => $this->getModelManager(),
],
])
thing is when i enable in frontend my filter it shows up correctly and when i type something i get error. In profiler (ajax request) i can see this problem
Could not find admin for code "".
Based on what i tried it looks like maybe something wrong with model_manager, i don't know if i sent it properly.
Any help how can i create custom ModelAutocompleteType which will work with sonata admin is really appreciate.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
