Commit 35b24f9c authored by mark burdett's avatar mark burdett
Browse files

Issue #2544688 by joshi.rohit100, mfb: SecureLoginConfigForm using static way for module handler

parent 21caf9b4
Loading
Loading
Loading
Loading
+33 −2
Changes for src/Form/SecureLoginConfigForm.php: 33 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ namespace Drupal\securelogin\Form;

use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -18,6 +19,36 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 */
class SecureLoginConfigForm extends ConfigFormBase {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Creates a new SecureLoginConfigForm object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
    parent::__construct($config_factory);
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('config.factory'),
      $container->get('module_handler')
    );
  }

  /**
   * {@inheritdoc}.
   */
@@ -95,7 +126,7 @@ class SecureLoginConfigForm extends ConfigFormBase {
      '#default_value' => $conf->get('form_user_register_form'),
      '#description' => $this->config('user.settings')->get('verify_mail') ? '' : t('Must be checked to enforce secure authenticated sessions.'),
    );
    \Drupal::moduleHandler()->alter('securelogin', $forms);
    $this->moduleHandler->alter('securelogin', $forms);
    foreach ($forms as $id => $item) {
      $form['forms']["form_$id"] = array(
        '#type' => 'checkbox',
@@ -136,7 +167,7 @@ class SecureLoginConfigForm extends ConfigFormBase {
      ->save();

    $forms = array();
    \Drupal::moduleHandler()->alter('securelogin', $forms);
    $this->moduleHandler->alter('securelogin', $forms);
    foreach ($forms as $id => $item) {
      $this->config('securelogin.settings')->set("form_$id", $form_state->getValue("form_$id"))->save();
    }