/**
* Implements hook_ENTITY_TYPE_view().
*/
function my_module_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('my_module')) {
$view = Views::getView('my_module_block');
if ($view) {
$block = $view->buildRenderable('block_1', [$entity->id()]);
if ($block) {
$build['my_module_block'] = [
'#type' => 'container',
'#attributes' => ['class' => ['views-block-wrapper']],
'content' => $block,
'#prefix' => '<h4>' . t('My block') . '</h4>',
];
}
}
}
}