From 7d0a298ebd35a02f977074872a138a29306a00fa Mon Sep 17 00:00:00 2001 From: LoganMMcDonald Date: Mon, 6 May 2024 16:37:09 -0700 Subject: [PATCH] fix lint --- .../src/Form/LoginSettingsForm.php | 225 +++++++++--------- .../UserLoginRouteSubscriber.php | 16 +- .../weather_login/src/UserRouteAccess.php | 36 +-- .../weather_login/weather_login.install | 40 ++-- .../weather_login/weather_login.module | 93 ++++---- 5 files changed, 207 insertions(+), 203 deletions(-) diff --git a/web/modules/weather_login/src/Form/LoginSettingsForm.php b/web/modules/weather_login/src/Form/LoginSettingsForm.php index dca64cfe0..d03eb0f6b 100644 --- a/web/modules/weather_login/src/Form/LoginSettingsForm.php +++ b/web/modules/weather_login/src/Form/LoginSettingsForm.php @@ -9,114 +9,119 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Configure USAgov Login Customizations settings for this site. + * Configure Weather Login Customizations settings for this site. */ -class LoginSettingsForm extends ConfigFormBase { - - /** - * State storage. - * - * @var \Drupal\Core\State\StateInterface - */ - private $state; - - /** - * LoginSettingsForm constructor. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * Configuration factory. - * @param \Drupal\Core\State\StateInterface $state - * State storage. - */ - public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) { - parent::__construct($config_factory); - $this->state = $state; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('state'), - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'weather_login_login_settings'; - } - - /** - * {@inheritdoc} - */ - protected function getEditableConfigNames() { - return ['weather_login.settings']; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $form['sso_login_path'] = [ - '#type' => 'textfield', - '#title' => $this->t('SSO Login Path'), - '#default_value' => $this->config('weather_login.settings') - ->get('sso_login_path'), - '#required' => FALSE, - ]; - - $form['sso_login_text'] = [ - '#type' => 'textfield', - '#title' => $this->t('Login Text'), - '#default_value' => $this->config('weather_login.settings') - ->get('sso_login_text'), - '#required' => FALSE, - ]; - - $form['sso_cancel_path'] = [ - '#type' => 'textfield', - '#title' => $this->t('SSO Cancel Path'), - '#default_value' => $this->config('weather_login.settings') - ->get('sso_cancel_path'), - '#required' => FALSE, - ]; - - $form['sso_cancel_text'] = [ - '#type' => 'textfield', - '#title' => $this->t('Cancel Text'), - '#default_value' => $this->config('weather_login.settings') - ->get('sso_cancel_text'), - '#required' => FALSE, - ]; - - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->config('weather_login.settings') - ->set('sso_login_path', $form_state->getValue('sso_login_path')) - ->save(); - - $this->config('weather_login.settings') - ->set('sso_login_text', $form_state->getValue('sso_login_text')) - ->save(); - - $this->config('weather_login.settings') - ->set('sso_cancel_path', $form_state->getValue('sso_cancel_path')) - ->save(); - - $this->config('weather_login.settings') - ->set('sso_cancel_text', $form_state->getValue('sso_cancel_text')) - ->save(); - - parent::submitForm($form, $form_state); - } - -} \ No newline at end of file +class LoginSettingsForm extends ConfigFormBase +{ + /** + * State storage. + * + * @var \Drupal\Core\State\StateInterface + */ + private $state; + + /** + * LoginSettingsForm constructor. + * + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * Configuration factory. + * @param \Drupal\Core\State\StateInterface $state + * State storage. + */ + public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) + { + parent::__construct($config_factory); + $this->state = $state; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) + { + return new static( + $container->get('config.factory'), + $container->get('state'), + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() + { + return 'weather_login_login_settings'; + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() + { + return ['weather_login.settings']; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) + { + $form['sso_login_path'] = [ + '#type' => 'textfield', + '#title' => $this->t('SSO Login Path'), + '#default_value' => $this->config('weather_login.settings') + ->get('sso_login_path'), + '#required' => false, + ]; + + $form['sso_login_text'] = [ + '#type' => 'textfield', + '#title' => $this->t('Login Text'), + '#default_value' => $this->config('weather_login.settings') + ->get('sso_login_text'), + '#required' => false, + ]; + + $form['sso_cancel_path'] = [ + '#type' => 'textfield', + '#title' => $this->t('SSO Cancel Path'), + '#default_value' => $this->config('weather_login.settings') + ->get('sso_cancel_path'), + '#required' => false, + ]; + + $form['sso_cancel_text'] = [ + '#type' => 'textfield', + '#title' => $this->t('Cancel Text'), + '#default_value' => $this->config('weather_login.settings') + ->get('sso_cancel_text'), + '#required' => false, + ]; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) + { + $this->config('weather_login.settings') + ->set('sso_login_path', $form_state->getValue('sso_login_path')) + ->save(); + + $this->config('weather_login.settings') + ->set('sso_login_text', $form_state->getValue('sso_login_text')) + ->save(); + + $this->config('weather_login.settings') + ->set('sso_cancel_path', $form_state->getValue('sso_cancel_path')) + ->save(); + + $this->config('weather_login.settings') + ->set('sso_cancel_text', $form_state->getValue('sso_cancel_text')) + ->save(); + + parent::submitForm($form, $form_state); + } +} diff --git a/web/modules/weather_login/src/RouteSubscriber/UserLoginRouteSubscriber.php b/web/modules/weather_login/src/RouteSubscriber/UserLoginRouteSubscriber.php index d8c6a43e1..28e8049cc 100644 --- a/web/modules/weather_login/src/RouteSubscriber/UserLoginRouteSubscriber.php +++ b/web/modules/weather_login/src/RouteSubscriber/UserLoginRouteSubscriber.php @@ -8,15 +8,15 @@ /** * User login route subscriber. */ -class UserLoginRouteSubscriber extends RouteSubscriberBase { - +class UserLoginRouteSubscriber extends RouteSubscriberBase +{ /** * {@inheritDoc} */ - protected function alterRoutes(RouteCollection $collection) { - if ($route = $collection->get('user.pass')) { - $route->setRequirement('_custom_access', 'Drupal\weather_login\UserRouteAccess::checkAccess'); + protected function alterRoutes(RouteCollection $collection) + { + if ($route = $collection->get('user.pass')) { + $route->setRequirement('_custom_access', 'Drupal\weather_login\UserRouteAccess::checkAccess'); + } } - } - -} \ No newline at end of file +} diff --git a/web/modules/weather_login/src/UserRouteAccess.php b/web/modules/weather_login/src/UserRouteAccess.php index dcf03fadb..06d6790e5 100644 --- a/web/modules/weather_login/src/UserRouteAccess.php +++ b/web/modules/weather_login/src/UserRouteAccess.php @@ -8,22 +8,22 @@ /** * User Route Access. */ -class UserRouteAccess { - - /** - * Callback for access check. - */ - public function checkAccess(AccountInterface $account) { - $config = \Drupal::config('weather_login.settings'); - $loginPath = $config->get('sso_login_path'); - - $forceLocalForm = \Drupal::state()->get('weather_login_local_form', 0); - - if ($loginPath && !$forceLocalForm) { - return AccessResult::forbidden(); +class UserRouteAccess +{ + /** + * Callback for access check. + */ + public function checkAccess(AccountInterface $account) + { + $config = \Drupal::config('weather_login.settings'); + $loginPath = $config->get('sso_login_path'); + + $forceLocalForm = \Drupal::state()->get('weather_login_local_form', 0); + + if ($loginPath && !$forceLocalForm) { + return AccessResult::forbidden(); + } + + return AccessResult::allowed(); } - - return AccessResult::allowed(); - } - -} \ No newline at end of file +} diff --git a/web/modules/weather_login/weather_login.install b/web/modules/weather_login/weather_login.install index f40b3f0a2..ff0788341 100644 --- a/web/modules/weather_login/weather_login.install +++ b/web/modules/weather_login/weather_login.install @@ -8,24 +8,24 @@ /** * Implements hook_requirements(). */ -function weather_login_requirements($phase) { - if ($phase === 'runtime') { - $config = \Drupal::config('weather_login.settings'); - if ($config->get('sso_login_path') === NULL || !$config->get('sso_login_path')) { - $severity = REQUIREMENT_WARNING; - $description = 'There is no configured value for the Weather Login module SSO Link Path, the SSO link will not function properly.'; - } - else { - $severity = REQUIREMENT_OK; - $description = 'The SSO Link has been configured.'; - } +function weather_login_requirements($phase) +{ + if ($phase === 'runtime') { + $config = \Drupal::config('weather_login.settings'); + if ($config->get('sso_login_path') === null || !$config->get('sso_login_path')) { + $severity = REQUIREMENT_WARNING; + $description = 'There is no configured value for the Weather Login module SSO Link Path'; + } else { + $severity = REQUIREMENT_OK; + $description = 'The SSO Link has been configured.'; + } - return [ - 'weather_login_sso_path' => [ - 'title' => 'Weather Login Module', - 'description' => $description, - 'severity' => $severity, - ], - ]; - } -} \ No newline at end of file + return [ + 'weather_login_sso_path' => [ + 'title' => 'Weather Login Module', + 'description' => $description, + 'severity' => $severity, + ], + ]; + } +} diff --git a/web/modules/weather_login/weather_login.module b/web/modules/weather_login/weather_login.module index c31a16926..3bfa72365 100644 --- a/web/modules/weather_login/weather_login.module +++ b/web/modules/weather_login/weather_login.module @@ -11,52 +11,51 @@ use Drupal\Core\Site\Settings; /** * Implements hook_form_FORM_ID_alter(). */ -function weather_login_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) { - - $config = \Drupal::config('weather_login.settings'); - $loginPath = $config->get('sso_login_path'); - $loginText = $config->get('sso_login_text'); - $cancelPath = $config->get('sso_cancel_path'); - $cancelText = $config->get('sso_cancel_text'); - - // Allow override for local login forms via $settings[] in settings.*.php - $settings_state = Settings::get('weather_login_local_form', 0); - if ($settings_state || $state) { - $state = 1; - } - - if ($loginPath) { - - if (!$state) { - $form['name']['#access'] = FALSE; - $form['pass']['#access'] = FALSE; - $form['actions']['#access'] = FALSE; - - $form['sso_button'] = [ - '#type' => 'html_tag', - '#tag' => 'a', - '#attributes' => [ - 'href' => $loginPath, - 'class' => ['usa-button'], - ], - '#value' => $loginText, - '#weight' => '-20', - ]; - - $form['sso_cancel_link'] = [ - '#type' => 'html_tag', - '#tag' => 'a', - '#attributes' => [ - 'href' => $cancelPath, - 'class' => ['cancel-link'], - ], - '#value' => $cancelText, - '#weight' => '-20', - '#prefix' => '', - ]; - - $form['#attributes']['class'][] = 'usa-list.usa-list--unstyled'; +function weather_login_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) +{ + $config = \Drupal::config('weather_login.settings'); + $loginPath = $config->get('sso_login_path'); + $loginText = $config->get('sso_login_text'); + $cancelPath = $config->get('sso_cancel_path'); + $cancelText = $config->get('sso_cancel_text'); + + // Allow override for local login forms via $settings[] in settings.*.php + $settings_state = Settings::get('weather_login_local_form', 0); + if ($settings_state || $state) { + $state = 1; + } + + if ($loginPath) { + if (!$state) { + $form['name']['#access'] = false; + $form['pass']['#access'] = false; + $form['actions']['#access'] = false; + + $form['sso_button'] = [ + '#type' => 'html_tag', + '#tag' => 'a', + '#attributes' => [ + 'href' => $loginPath, + 'class' => ['usa-button'], + ], + '#value' => $loginText, + '#weight' => '-20', + ]; + + $form['sso_cancel_link'] = [ + '#type' => 'html_tag', + '#tag' => 'a', + '#attributes' => [ + 'href' => $cancelPath, + 'class' => ['cancel-link'], + ], + '#value' => $cancelText, + '#weight' => '-20', + '#prefix' => '', + ]; + + $form['#attributes']['class'][] = 'usa-list.usa-list--unstyled'; + } } - } }