From 0f987fe5334395a7079db144ca66203ef4fa32c1 Mon Sep 17 00:00:00 2001
From: Nejc <nejc.koporec@agiledrop.com>
Date: Fri, 30 Mar 2018 09:17:11 +0200
Subject: [PATCH] Fix dependency injection issue

---
 src/Form/ChosenConfigForm.php | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/Form/ChosenConfigForm.php b/src/Form/ChosenConfigForm.php
index 34e85f1..ce71553 100644
--- a/src/Form/ChosenConfigForm.php
+++ b/src/Form/ChosenConfigForm.php
@@ -2,17 +2,45 @@
 
 namespace Drupal\chosen\Form;
 
+use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Form\ConfigFormBase;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\system\Form;
 use Drupal\Core\Url;
 use Drupal\Core\Link;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Extension\ThemeHandler;
 
 /**
  * Implements a ChosenConfig form.
  */
 class ChosenConfigForm extends ConfigFormBase {
 
+  /**
+   * Theme handler.
+   *
+   * @var \Drupal\Core\Extension\ThemeHandler
+   *   Theme handler.
+   */
+  protected $themeHandler;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(ConfigFactoryInterface $config_factory, ThemeHandler $themeHandler) {
+    parent::__construct($config_factory);
+    $this->themeHandler = $themeHandler;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('config.factory'),
+      $container->get('theme_handler')
+    );
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -212,9 +240,7 @@ class ChosenConfigForm extends ConfigFormBase {
     $options = [];
 
     // Get a list of available themes.
-    $theme_handler = \Drupal::service('theme_handler');
-
-    $themes = $theme_handler->listInfo();
+    $themes = $this->themeHandler->listInfo();
 
     foreach ($themes as $theme_name => $theme) {
       // Only create options for enabled themes.
-- 
2.15.1

