1

Database stores gender field as smallint. Easyadmin render fields based on entity properties. I won't simply put a string eg. "Male" instead of 1.

I tried to override AdminController and override methods like createEditForm() and createEntityFormBuilder() but ended up with "Call to a member function handleRequest() on null"

easy_admin:
  entities:
    User:
      controller: App\Controller\CustomAdminController
      class: App\Entity\User
      form:
        title: "Details"
        fields:
- { property: 'userProfile.gender', type: 'text', label: 'Gender', 
type_options:{ disabled: true, required: false} }
Dave
  • 31
  • 2

2 Answers2

0

You could try changing your getGender() and setGender() methods to handle the conversion in your entity.

public function getGender(): ?string
{
  if (0 === $this->gender){
    return 'Female';
  }
  if (1 === $this->gender){
    return 'Male';
  }
  if (2 === $this->gender){
    return 'Other';
  }
}
public function setGender(string $gender): self
{
  if ('female'=== strtolower($gender)){ 
    $this->gender = 0;
  } else if ('male'=== strtolower($gender)){ 
    $this->gender = 1;
  } else { 
    $this->gender = 2;
  }
  return $this;
}
Arleigh Hix
  • 9,990
  • 1
  • 14
  • 31
  • I know about this possibility, but i forgot to mention that there's API for the mobile app, so messing in entties setters and getters would mess endpoints. Currently I switched to SonataAdmin bundle, and easily solve the problem. – Dave Sep 18 '19 at 09:05
0

I switched to SonataAdmin Bundle which provides an easy way to do it right.

Dave
  • 31
  • 2