Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Last active May 30, 2018 15:54
Show Gist options
  • Save webdevilopers/1c830e5c2c004a794daf to your computer and use it in GitHub Desktop.
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
{% 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 %}
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
{{ object.gender == constant('GENDER_FEMALE', object) ? 'Mrs' : 'Mr' }}
{{ object.firstname }} {{ object.lastname }}
{% endblock %}
<?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'
));
}
}
<?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