Customizing the display of properties on a rendered entity I have a custom entity with a large amount of properties on it.

We want to format these entity properties to look a certain way, without modifying the underlying data in the table.

What is the most idiomatic (the most Drupal) way of doing it?

We're trying to put an Entity Reference of this custom entity on a node and render only a few fields - with a form of preprocessing or something along those lines so that we can control the ultimate output.

I can get the fields to show with this key => value pair in the entity array in hook_entity_info():

'extra fields controller class' =&gt; 'EntityDefaultExtraFieldsController',


But it doesn't seem to give me any control over the output.

Alternatively, I can put all of the properties into $entity->content in hook_entity_view() as such:

foreach ($entity as $field_name =&gt; $property) {
  if (in_array($field_name, $properties)) {
    $entity-&gt;content[$field_name] = array("#markup" =&gt; $property . "&lt;br /&gt;");
  }


But this doesn't seem very idiomatic.

This seems like a problem that I can't find a lot of resources on.
We're trying to put an Entity Reference of this custom entity on a node and render only a few fields - with a form of preprocessing or something along those lines so that we can control the ultimate output.


Sounds like hook_entity_view is what you want. Use "teaser" or create a new view mode, and attach the reference using the given view mode, then implement your logic to render the properties as you like.

Alternatively / additionally, you could look at Display Suite and DS Extras which will give you more flexibility to expose properties via DS custom fields or in field templates.