I added a login form to a node with following code :
function my_theme_preprocess_node(&$variables) {
$node = $variables['node'];
$variables['login_form'] = FALSE;
$variables['username'] = FALSE;
if(Drupal::currentUser()->isAnonymous()) {
$form = Drupal::formBuilder()->getForm(\Drupal\user\Form\UserLoginForm::class);
$variables['login_form'] = Drupal::service('renderer')->renderPlain($form); // renderRoot
} else {
$variables['username'] = Drupal::currentUser()->getDisplayName();
}
}
If I change the line
$variables['login_form'] = Drupal::service('renderer')->renderPlain($form);
to
$variables['login_form'] = Drupal::service('renderer')->renderRoot($form);
I can't see any difference. Both seem to work either.
I read the docs, the latter mostly checks
Whether we're currently in a ::renderRoot() call.
but it is not very explicit about why /when this check is useful and so when to use the former or latter function ?