Last active
May 30, 2018 15:54
-
-
Save webdevilopers/1c830e5c2c004a794daf to your computer and use it in GitHub Desktop.
Create custom template list field for title and name with SonataUserBundle User Entity GENDER constants in SonataAdminBundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %} | |
{% block field %} | |
{% if object.gender == constant('Application\\Sonata\\UserBundle\\Entity\\User::GENDER_FEMALE') %} | |
Mrs | |
{% else %} | |
Mr | |
{% endif %} | |
{{ object.firstname }} {{ object.lastname }} | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %} | |
{% block field %} | |
{{ object.gender == constant('GENDER_FEMALE', object) ? 'Mrs' : 'Mr' }} | |
{{ object.firstname }} {{ object.lastname }} | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Sonata\UserBundle\Admin; | |
use Sonata\UserBundle\Admin\Model\UserAdmin as SonataUserAdmin; | |
use Sonata\AdminBundle\Datagrid\ListMapper; | |
class UserAdmin extends SonataUserAdmin | |
{ | |
protected function configureListFields(ListMapper $listMapper) | |
{ | |
$listMapper | |
->addIdentifier('username') | |
->add('title_name', 'string', array( | |
'template' => 'ApplicationSonataUserBundle:UserAdmin:list__title_name.html.twig' | |
)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sonata\UserBundle\Model; | |
interface UserInterface extends \FOS\UserBundle\Model\UserInterface | |
{ | |
const GENDER_FEMALE = 'f'; | |
const GENDER_MALE = 'm'; | |
const GENDER_UNKNOWN = 'u'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment