Hey, I'm real in trouble because I have a project which have to go live in next days. How can I tell EasyAdminBundle a custom data-provider for a "choice" field?
I have a Method which returns an array, this array should be shown in form as choice field.
I am new to easyadmin myself so this might not be the best solution. If hardcoding of choices is an option you can do following:
form:
fields:
- { property: 'gender', type:'choice', type_options: {choices: {'1':'Male', '2':'Female'}}}
This will show a choice with Male/Female option.
@amit0rana you are right ... but @SebTM has a method that generates the list of options dynamically. In this case, you must create your own AdminController (which is very easy to do) and then override the method that creates the form for your entity:
class AdminController extends BaseAdminController
{
public function create<EntityName>EntityFormBuilder($entity, $view)
{
$formBuilder = parent::createEntityFormBuilder($entity, $view);
// get the list of choices from your application and add the form field for them
$formBuilder->add(...);
return $formBuilder;
}
}
@amit0rana Thanks for your help but in this case I really need a dynamic solution as the drop-down offers some paths which depends on FTP-Uploads
@javiereguiluz Thanks for your help!
Most helpful comment
@amit0rana you are right ... but @SebTM has a method that generates the list of options dynamically. In this case, you must create your own AdminController (which is very easy to do) and then override the method that creates the form for your entity: