-1

I'm trying to show Full name column with firstName and lastName from entity. How can I do?

Here is my Entity and Admin.php:

class test{

private firstName;

//another properties

private lastName;

}

Admin

protected function configureListFields(ListMapper $listMapper){
$listMapper
  ->add('id',null)
  ->add('Full name'); //I want to show the column like this (Full name = firstName + lastName)
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ben
  • 75
  • 1
  • 14
  • 2
    See https://stackoverflow.com/a/27223536/8237207. It's the same question as yours with an answer! – Simon Brink Jun 04 '19 at 11:40
  • Possible duplicate of [Sonata 2 display 2 fields in the same column](https://stackoverflow.com/questions/27220524/sonata-2-display-2-fields-in-the-same-column) – Simon Brink Jun 04 '19 at 11:43

1 Answers1

0

try to use this inside your user Entity:

    /**
 * Get the full username if first and last name are set,
 * the username otherwise
 *
 * @return string
 */
public function getFullUsername(): string
{
    if ($this->firstname && $this->lastname) {
        return $this->firstname . ' ' . $this->lastname;
    }

    return $this->username;
}
Ali Mhanna
  • 199
  • 2
  • 15