The function buildRow
returns a render array. You can put simple strings directly in the array, because later it will be put in another html structure like a table. An example from core, where it is used both ways (CommentTypeListBuilder.php):
public function buildRow(EntityInterface $entity) {
$row['type'] = $entity->label();
$row['description']['data'] = ['#markup' => $entity->getDescription()];
return $row + parent::buildRow($entity);
}
So using the '#markup' element is optional. You can use it to be on the safe side, when you don't know how your render array is processed.
For complex elements you need a render element. The method view() would generates this:
$row['email'] = $entity->email->view();
But this does not work. The problem seems to be in the custom entity. According to the error message there is a call to an undefined method render
, which should be defined in MyEntity
. Your entity does not know how to handle the email field.
If you don't want to theme the field, you can use the value as markup:
$row['email']['#markup'] = $entity->email->value;
Or you can put the field as an object:
$row['email'] = $entity->email;
Or you can build your own render array, for example as a link:
$row['title'] = array(
'#type' => 'link',
'#title' => $entity->label(),
'#url' => $uri,
);