I have an entity called SyncJob and it contains the following fields:

  • id
  • progress: integer
  • total: integer

I need to customize its view page (canonical, not the collections one) to show the following fields of one SyncJob entity:

  • id
  • status ('success' if progress == total, '' if progress < total)
  • percentage: progress / total * 100% as percentage

I have tried adding field plugins and altering views data but these seem only work on the collections view. Is it possible to achieve these without writing HTML? If so, what kind of files do I need to create or modify?

  • You can have two Views, one for collections and one for canonicals.
    – 4k4
    May 21 at 6:38
  • I used the hook_entity_view() to solve the problem. Added two elements to display status and percentage.
    – Roi1001
    May 21 at 8:58
  • OK, this works if you have not created a View to override the canonical route. What is your question then?
    – 4k4
    May 21 at 9:20
  • Thanks for your reply. I use the default canonical page to display the entity data and was wondering if computed fields can be added to the entity and displayed on the view automatically. Then I found out this can be done by simply changing the render array. Problem solved.
    – Roi1001
    May 21 at 9:36
  • @4k4 I take this isn't a question about views.
    – apaderno
    May 21 at 11:01

There are modules you can find that help you do that. Search for "computed field" and similar.

You can then adjust your node form (Manage form display) not to show the computed fields, and on the Manage display page (default view mode is what you call canonical, you can create more of them though) adjust the fields so only the computed ones are shown.

One example: Computed Field

Not the answer you're looking for? Browse other questions tagged or ask your own question.