Skip to content
Snippets Groups Projects
Commit 923556f4 authored by Mrinalini Kumari's avatar Mrinalini Kumari Committed by howard ge
Browse files

Issue #3362612 by nitin_lama, mrinalini9, Shanu Chouhan, Ashutosh Ahirwal,...

Issue #3362612 by nitin_lama, mrinalini9, Shanu Chouhan, Ashutosh Ahirwal, thakurnishant_06, apaderno: Fix the issues reported by phpcs
parent 2deb4885
Branches 1.0.x
No related tags found
No related merge requests found
......@@ -3,4 +3,3 @@ type: module
description: 'Fake login module.'
core_version_requirement: ^9 || ^10
package: 'Other'
......@@ -6,4 +6,4 @@ fakelogin.config:
requirements:
_permission: 'administer site configuration'
route_callbacks:
- '\Drupal\fakelogin\Routing\FakeLoginRoutes::routes'
\ No newline at end of file
- '\Drupal\fakelogin\Routing\FakeLoginRoutes::routes'
......@@ -2,4 +2,4 @@ services:
fakelogin.route_subscriber:
class: Drupal\fakelogin\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
\ No newline at end of file
- { name: event_subscriber }
......@@ -4,6 +4,8 @@ namespace Drupal\fakelogin\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure settings for fake login.
......@@ -12,19 +14,45 @@ use Drupal\Core\Form\FormStateInterface;
*/
class FakeLoginConfigForm extends ConfigFormBase {
/**
* The route building service.
*
* @var \Drupal\Core\Routing\RouteBuilderInterface
*/
protected $routeBuilder;
/**
* Constructs a new Drupal\fakelogin\Form\FakeLoginConfigForm object.
*
* @param \Drupal\Core\Routing\RouteBuilderInterface $routeBuilder
* The router builder service.
*/
public function __construct(RouteBuilderInterface $routeBuilder) {
$this->routeBuilder = $routeBuilder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('router.builder')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'fakelogin_config_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['fakelogin.settings'];
}
}
/**
* {@inheritdoc}
......@@ -54,9 +82,9 @@ class FakeLoginConfigForm extends ConfigFormBase {
$config = $this->config('fakelogin.settings');
$config->set('login_path', $form_state->getValue('login_path'));
$config->save();
// rebuild the router.
\Drupal::service('router.builder')->rebuild();
$this->routeBuilder->rebuild();
return parent::submitForm($form, $form_state);
}
}
......@@ -36,7 +36,7 @@ class FakeLoginForm extends FormBase {
'autofocus' => 'autofocus',
],
];
$form['pass'] = [
'#type' => 'password',
'#title' => $this->t('Password'),
......@@ -44,10 +44,13 @@ class FakeLoginForm extends FormBase {
'#description' => $this->t('Enter the password that accompanies your username.'),
'#required' => TRUE,
];
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Log in')];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Log in'),
];
return $form;
}
......@@ -62,7 +65,7 @@ class FakeLoginForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
//$this->messenger()->addStatus($this->t('Your username is @username', ['@username' => $form_state->getValue('name')]));
}
}
\ No newline at end of file
}
......@@ -17,27 +17,23 @@ class FakeLoginRoutes {
$route_collection = new RouteCollection();
$config = \Drupal::config('fakelogin.settings');
$real_login_path = $config->get('login_path') ??"/real-login-path";
// Add real login route.
$real_login_path = $config->get('login_path') ?? "/real-login-path";
$real_login_route = new Route(
$real_login_path,
// Route defaults:
[
'_form' => '\Drupal\user\Form\UserLoginForm',
'_title' => 'Log in',
],
// Route requirements:
[
'_user_is_logged_in' => 'FALSE',
],
//Route options
[
'_maintenance_access' => TRUE,
]
]
);
// Add the route.
$route_collection->add('fakelogin.reallogin', $real_login_route);
return $route_collection;
}
}
......@@ -15,7 +15,7 @@ class RouteSubscriber extends RouteSubscriberBase {
*/
protected function alterRoutes(RouteCollection $collection) {
// replace default user login with a fake form.
// Replace the default user login form with a fake form.
if ($route = $collection->get('user.login')) {
$route->setDefault('_form', '\Drupal\fakelogin\Form\FakeLoginForm');
}
......@@ -30,4 +30,5 @@ class RouteSubscriber extends RouteSubscriberBase {
$route->setRequirement('_access', 'FALSE');
}
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment