/**
* Implements hook_ENTITY_TYPE_view().
*/
function my_module_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('my_block')) {
$block = \Drupal::service('plugin.manager.block')->createInstance('my_module_my_block');
if ($block) {
$build['my_module_my_block'] = [
'#type' => 'container',
'#attributes' => ['class' => ['block-wrapper']],
'content' => $block->build(),
'#prefix' => '<h4>' . t('My block') . '</h4>',
];
}
}
}