Code snippet that can be used to show role options to users and hide administrator role in user registration form in Drupal 8.
<?php
/**
* @param $form
* @param $form_state
* @param $form_id
*/
function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id)
{
unset($form['account']['roles']['#options']['administrator']);
$form['account']['roles']['#access'] = TRUE;
}
With this snippet:
users with the permission of 'administer users' can assign roles on the user registration form.
Hide the 'administrator' role for your users.