What I need to do is very simple:
Have the enabled checkbox checked by default at user creation time in the user admin edit form.
I have already extended SonataUserAdminBundle and done some successful modifications.
I tried to enable it in the extended User Entity
class User extends AbstractedUser implements UserInterface
{
#...
protected $enabled = true;
#...
}
But nothing changes.
How to enable a user by default at creation time ?
Also I tried to check it from the user admin class
class UserAdmin extends BaseUserAdmin
{
#...
protected function configureFormFields(FormMapper $formMapper)
{
#...
$formMapper->with('Security')
->add('enabled', null
, array('required' => false, 'checked' => 'yes'))
->end();
}
#...
}
But not a good idea because it will always come checked.
You can set it in the constructor of your entity:
class User extends AbstractedUser implements UserInterface
{
#...
protected $enabled;
#...
public function __construct()
{
$this->enabled = true;
}
#...
}
Remember to call the parent constructor and set your option after that:
public function __construct()
{
parent::__construct();
$this->enabled = true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.