Commit 436f53cf authored by jcnventura's avatar jcnventura Committed by Joao Ventura
Browse files

Issue #2478487 by jcnventura, sun: Modify the core user login form to show external providers

parent 6dc96d77
always_save_userinfo: true
connect_existing_users: false
override_registration_settings: false
user_login_display: 'hidden'
userinfo_mappings:
timezone: zoneinfo
......@@ -13,6 +13,9 @@ openid_connect.settings:
override_registration_settings:
type: boolean
label: 'Override registration settings'
user_login_display:
type: string
label: 'Show external providers in user login form'
userinfo_mappings:
type: mapping
label: 'OpenID Connect settings'
......
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
......@@ -135,6 +136,36 @@ function openid_connect_form_user_profile_form_alter(&$form, &$form_state) {
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function openid_connect_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$user_login_display = \Drupal::config('openid_connect.settings')
->get('user_login_display');
if ($user_login_display != 'hidden') {
$openid_form = \Drupal::formBuilder()->getForm('Drupal\openid_connect\Form\OpenIDConnectLoginForm');
switch ($user_login_display) {
case 'above':
$form['#prefix'] = \Drupal::service('renderer')->render($openid_form);
break;
case 'below':
$form['#suffix'] = \Drupal::service('renderer')->render($openid_form);
break;
case 'replace':
// Do nothing in case the query contains the 'showcore' parameter.
$query = \Drupal::request()->query;
if (!$query->has('showcore')) {
// Replace the user login form with the google domain login button.
$form = $openid_form;
}
break;
}
}
}
/**
* Saves user profile information into a user account.
*
......
......@@ -179,6 +179,19 @@ class OpenIDConnectSettingsForm extends ConfigFormBase implements ContainerInjec
'#default_value' => $settings->get('connect_existing_users'),
];
$form['user_login_display'] = array(
'#type' => 'radios',
'#title' => $this->t('OpenID buttons display in user login form'),
'#options' => array(
'hidden' => $this->t('Hidden'),
'above' => $this->t('Above'),
'below' => $this->t('Below'),
'replace' => $this->t('Replace'),
),
'#description' => $this->t("Modify the user login form to show the the OpenID login buttons. If the 'Replace' option is selected, only the OpenID buttons will be displayed. In this case, pass the 'showcore' URL parameter to return to a password-based login form."),
'#default_value' => $settings->get('user_login_display'),
);
$form['userinfo_mappings'] = [
'#title' => $this->t('User claims mapping'),
'#type' => 'fieldset',
......@@ -257,6 +270,7 @@ class OpenIDConnectSettingsForm extends ConfigFormBase implements ContainerInjec
->set('connect_existing_users', $form_state->getValue('connect_existing_users'))
->set('override_registration_settings', $form_state->getValue('override_registration_settings'))
->set('userinfo_mappings', $form_state->getValue('userinfo_mappings'))
->set('user_login_display', $form_state->getValue('user_login_display'))
->save();
// Get clients' enabled status.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment