Creae custom entity each time other entities are viewed

by Thomas0878   Last Updated January 12, 2018 16:07 PM

I would like to create a kind of log entry each time an entity is viewed. For this purpose I created a custom entity 'AccessTime' with the following fields: - Viewer (entity reference on user) - Viewed_Entity (entity reference) - Access_time (timestamp)

For a custom entity 'tutorial' I create a custom view builder extending EntityViewBuilder and in the view function I create a new AccessTime entity. This works fine.

I have two questions: 1. The tutorial entity is also available to users using views rendering fields. In this case the AccessTime entity is not created. How can I achieve this? 2. For core and contributed entities I am using hook_entity_view. Is there any other way to trigger the creation of my AccessTime entity?

Tags : views 8 entities


Related Questions