Reputation: 33
I display the list form of Sonata. I have 2 fields : firstname, lastname. I want to display 2 fields in the same column.
Currently, I'm doing
$listMapper->add('firstname', 'text', array('label' => 'First Name'))
->add('lastname', 'text', array('label' => 'Last Name'));
How can I combine 2 fields in one without to change the Entity
Upvotes: 1
Views: 2783
Reputation: 1884
This is how i do it:
Say firstname
and lastname
are properties of User. In your entity class User, just add:
/**
* @return string
*/
public function getFullname()
{
return sprintf("%s %s", $this->getFirstname(), $this->getLastname());
}
Then in your admin class:
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
...
->add('fullname', null, array('label' => 'Full Name'))
}
Upvotes: 5
Reputation: 4119
You could possibly use a data transformer.
Or (and this doesn't seem like a good idea to me at all)you could do something like:
Upvotes: 0