You can use hook_entity_load to add fields to the user object like so:
function mymodule_entity_load($entities, $type)
{
if ($type == 'user' )
{
foreach($entities as $e) {
$e->myField = 'hello';
}
}
}
That will allow me to do this in twig:
{{ user.myField }}
This is quite useful, but it would be great if I could do this:
{{ user.getActivity() }}
Or more specifically:
<h1>Members</h1>
<ul>
{% for activity in user.getActivity() %}
<li>{{ activity.time }}</li>
{% endfor %}
</ul>
Is there a way to add a "function" in this way?