diff --git a/js/user-login-min.js b/js/user-login-min.js index da591c4b151d918bd61c3df4540686e5dfdcf638..5365d9382e7ef1134927a5113998f75603d68fba 100644 --- a/js/user-login-min.js +++ b/js/user-login-min.js @@ -1 +1 @@ -!function(l,i){i.behaviors.uwFdsuThemeRespUserLogin={attach:function(i,n){l("#user-login-form").css("display","none"),l("#local-login-link").click(function(){l("#user-login-form").css("display","block"),l("#local-login-link").css("display","none"),l("#adfs-login-link").css("display","none"),l("#edit-submit").val("Log In Locally")}),l("#adfs-login-link").click(function(){l("#edit-simplesamlphp-auth-login-link")[0].click()})}}}(jQuery,Drupal); +!function(l,i){i.behaviors.uwFdsuThemeRespUserLogin={attach:function(i,n){l("#edit-simplesamlphp-auth-login-link").length&&(l("#user-login-form").css("display","none"),l("#user-login-form").after('<button id="adfs-login-link" class="button--primary">Log in via ADFS</button> <button id="local-login-link" class="button--medium">Log in locally</button>'),l("#edit-submit").val("Log in locally"),l("#local-login-link").click(function(){l("#user-login-form").css("display","block"),l("#local-login-link").css("display","none"),l("#adfs-login-link").css("display","none"),l("#edit-name").focus()}),l("#adfs-login-link").click(function(){l("#edit-simplesamlphp-auth-login-link")[0].click()}))}}}(jQuery,Drupal); diff --git a/js/user-login.js b/js/user-login.js index aadf7cc3e69950dc42e8b818f283659a726edbed..c0f36da198dae9910c29099567cc49f3f022d698 100644 --- a/js/user-login.js +++ b/js/user-login.js @@ -1,16 +1,28 @@ (function ($, Drupal) { Drupal.behaviors.uwFdsuThemeRespUserLogin = { attach: function (context, settings) { - $('#user-login-form').css('display', 'none'); - $('#local-login-link').click(function () { - $('#user-login-form').css('display', 'block'); - $('#local-login-link').css('display', 'none'); - $('#adfs-login-link').css('display', 'none'); - $('#edit-submit').val('Log In Locally'); - }); - $('#adfs-login-link').click(function () { - $('#edit-simplesamlphp-auth-login-link')[0].click(); - }); + // Don't do anything if SimpleSAML isn't enabled. + if ($('#edit-simplesamlphp-auth-login-link').length) + { + // Hide the normal login form. + $('#user-login-form').css('display', 'none'); + // Add buttons (using JS because they don't work without JS) + $('#user-login-form').after('<button id="adfs-login-link" class="button--primary">Log in via ADFS</button> <button id="local-login-link" class="button--medium">Log in locally</button>'); + // Update the existing login form's link text. + $('#edit-submit').val('Log in locally'); + // If the local login link is clicked, show the normal login form and hide the buttons. + // Be nice to the user, and put focus on the name field so they can just start typing. + $('#local-login-link').click(function () { + $('#user-login-form').css('display', 'block'); + $('#local-login-link').css('display', 'none'); + $('#adfs-login-link').css('display', 'none'); + $('#edit-name').focus(); + }); + // If the ADFS login link is clicked, click on the original log in with ADFS link. + $('#adfs-login-link').click(function () { + $('#edit-simplesamlphp-auth-login-link')[0].click(); + }); + } } }; })(jQuery, Drupal); diff --git a/templates/form/form--user-login-form.html.twig b/templates/form/form--user-login-form.html.twig deleted file mode 100644 index da369f56a3115a29dedbd966de9721b91757ad41..0000000000000000000000000000000000000000 --- a/templates/form/form--user-login-form.html.twig +++ /dev/null @@ -1,17 +0,0 @@ -{# -/** - * @file - * Theme override for a 'form' element. - * - * Available variables - * - attributes: A list of HTML attributes for the wrapper element. - * - children: The child elements of the form. - * - * @see template_preprocess_form() - */ -#} -<form{{ attributes }}> - {{ children }} -</form> -<button id="adfs-login-link" class="button--primary">Log In Via ADFS</button> -<button id="local-login-link">Log In Locally</button> diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index b145022aa0493cde8733fe578205679b252df58d..2a553dcc6654879f0505b0d47c656e9b2bb1f086 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -24,32 +24,6 @@ require_once dirname(__FILE__) . '/includes/navigation.inc'; require_once dirname(__FILE__) . '/includes/taxonomy.inc'; require_once dirname(__FILE__) . '/includes/views.inc'; -/** - * Implements hook_theme_suggestions_form_alter(). - * - * Add suggestion for forms. - */ -function uw_fdsu_theme_resp_theme_suggestions_form_alter(array &$suggestions, array $variables) { - - // form--user-login-form.html.twig. - $suggestions[] = 'form__' . str_replace('-', '_', $variables['element']['#id']); -} - -/** - * Implements hook_theme(). - * - * Custom twig for forms. - */ -function uw_fdsu_theme_resp_theme($existing, $type, $theme, $path) { - - return [ - 'form__user-login-form' => [ - '#theme' => 'form--user-login-form', - 'render element' => 'form', - ], - ]; -} - /** * Implements hook_preprocess_HOOK(). *