I'm a first-time stackexchange user, long time Drupal 6 developer.
I'm just starting playing with Drupal 8 and I know I'm going to love it when I get used to working in it but right now I'm in that frustration phase where it's unfamiliar again and I can't do even the simple things! I wonder if you can help.
I would like to add dynamic content (probably just #markup) to the user's main tab. At the moment, the user tab only contains the familiar text 'Member for xxx'.
Under Drupal 6 I just handled hook_user, something like:
function mymodule_user($type, &$edit, &$user, $category = NULL) {
switch ($type) {
case 'view':
$user->content['the_time'] = array(
'#type' => 'markup',
'#value' => 'Epoch = <b>' . time() . '</b>',
'#weight' => 100,
);
break;
}
}
(I've not checked the above actually runs, but it's a modified version of something I'm using on a live site).
What's the equivalent under Drupal 8? I'm looking at the following:
function mymodule_user_view(array &$build, UserInterface $account, EntityViewDisplayInterface $display) {
$build['the_time'] = array(
'#type' => 'item',
'#markup' => 'Epoch = <b>' . time() . '</b>',
);
}
Although this works (after clearing the caches) I don't think this is the recommended way to do it, as I'm not seeing dynamic content, the hook is only called once and the text is cached.
I really hope someone can point me in the right direction!