Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
loganmcdonald-noaa committed May 6, 2024
1 parent 170d17f commit 7d0a298
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 203 deletions.
225 changes: 115 additions & 110 deletions web/modules/weather_login/src/Form/LoginSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

}
}
36 changes: 18 additions & 18 deletions web/modules/weather_login/src/UserRouteAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
}
40 changes: 20 additions & 20 deletions web/modules/weather_login/weather_login.install
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];
}
}
return [
'weather_login_sso_path' => [
'title' => 'Weather Login Module',
'description' => $description,
'severity' => $severity,
],
];
}
}
Loading

0 comments on commit 7d0a298

Please sign in to comment.