I'd replace this whole block with a call to `_elgg_services()->views->viewEntityAspect()` (`@access private` for now)