Commit b5f6213c authored by Marina Victória's avatar Marina Victória Committed by bartvig
Browse files

Issue #3258332 by victoria-marina, j-barnes: Fix Dependency Injection Issues

parent f72562aa
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -4,12 +4,12 @@ namespace Drupal\siteimprove\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use GuzzleHttp\Client;
use Drupal\Core\Messenger\Messenger;
use Drupal\siteimprove\Plugin\SiteimproveDomainManager;
use Drupal\siteimprove\SiteimproveUtils;
use Drupal\taxonomy\Entity\Vocabulary;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Cache\Cache;
@@ -49,16 +49,24 @@ class SettingsForm extends ConfigFormBase {
   */
  protected $httpClient;

  /**
   * The vocabulary storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $vocabularyStorage;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, SiteimproveUtils $siteimprove, SiteimproveDomainManager $pluginManagerSiteimproveDomain, Messenger $messenger, Client $httpClient) {
  public function __construct(ConfigFactoryInterface $config_factory, SiteimproveUtils $siteimprove, SiteimproveDomainManager $pluginManagerSiteimproveDomain, Messenger $messenger, Client $httpClient, EntityStorageInterface $vocabulary_storage) {
    parent::__construct($config_factory);

    $this->siteimprove = $siteimprove;
    $this->pluginManagerSiteimproveDomain = $pluginManagerSiteimproveDomain;
    $this->messenger = $messenger;
    $this->httpClient = $httpClient;
    $this->vocabularyStorage = $vocabulary_storage;
  }

  /**
@@ -71,7 +79,8 @@ class SettingsForm extends ConfigFormBase {
      $container->get('siteimprove.utils'),
      $container->get('plugin.manager.siteimprove_domain'),
      $container->get('messenger'),
      $container->get('http_client')
      $container->get('http_client'),
      $container->get('entity_type.manager')->getStorage('taxonomy_vocabulary')
    );
  }

@@ -183,7 +192,7 @@ class SettingsForm extends ConfigFormBase {

    $form['prepublish']['api_username'] = [
      '#type' => 'textfield',
      '#description' => 'SiteImprove API username',
      '#description' => $this->t('SiteImprove API username'),
      '#default_value' => $config->get('api_username'),
      '#states' => [
        'enabled' => [
@@ -196,7 +205,7 @@ class SettingsForm extends ConfigFormBase {

    $form['prepublish']['api_key'] = [
      '#type' => 'textfield',
      '#description' => 'SiteImprove API key',
      '#description' => $this->t('SiteImprove API key'),
      '#default_value' => $config->get('api_key'),
      '#states' => [
        'enabled' => [
@@ -289,10 +298,9 @@ class SettingsForm extends ConfigFormBase {
        ],
      ],
    ];
    $vocabulary_names = taxonomy_vocabulary_get_names();
    $vocabularies = Vocabulary::loadMultiple($vocabulary_names);

    $taxonomy_options = [];
    foreach ($vocabularies as $vocabulary) {
    foreach ($this->vocabularyStorage->loadMultiple() as $vocabulary) {
      $taxonomy_options[$vocabulary->id()] = $vocabulary->label();
    }
    $form['prepublish']['taxonomies']['enabled_taxonomies'] = [