Custom fields in user's default tab 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, &amp;$edit, &amp;$user, $category = NULL) {
  switch ($type) {
    case 'view':
      $user-&gt;content['the_time'] = array(
        '#type' =&gt; 'markup',
        '#value' =&gt; 'Epoch = &lt;b&gt;' . time() . '&lt;/b&gt;',
        '#weight' =&gt; 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 &amp;$build, UserInterface $account, EntityViewDisplayInterface $display) {
  $build['the_time'] = array(
    '#type' =&gt; 'item',
    '#markup' =&gt; 'Epoch = &lt;b&gt;' . time() . '&lt;/b&gt;',
  );
}


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!
The question how to put a custom field in the user tab is already answered, btw you don't need '#type', when using '#markup' in drupal 8.

As you said at the end, this is a caching issue. In general it is not a good idea to put the time in the html of every page, you better do this in javascript. If you don't care about performance, then you can disable the cache:

$build['#cache']['max-age'] = 0;


This does not work for anonymous users, because in drupal 8 there is also the page cache enabled by default. If you deliver a different page on every request, you don't need this module and you can uninstall it.

If you want to disable it only for the user default tab, then use this command:

\Drupal::service('page_cache_kill_switch')-&gt;trigger();