Skip to content

Commit

Permalink
1062: Use dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuaitk committed Jun 27, 2024
1 parent 012d848 commit 9b1e54e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions modules/os2forms_encrypt/os2forms_encrypt.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ services:
os2forms_encrypt.form_helper:
class: Drupal\os2forms_encrypt\Helper\FormHelper

os2forms_encrypt.settings_form:
class: Drupal\os2forms_encrypt\Form\SettingsForm
arguments: ['@config.factory', '@encrypt.encryption_profile.manager']
28 changes: 25 additions & 3 deletions modules/os2forms_encrypt/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Drupal\os2forms_encrypt\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\encrypt\EncryptionProfileManager;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class SettingsForm.
Expand All @@ -20,6 +23,27 @@ class SettingsForm extends ConfigFormBase {
*/
public static string $configName = 'os2forms_encrypt.settings';

/**
* The config factory.
*
* @var \Drupal\encrypt\EncryptionProfileManager
*/
private EncryptionProfileManager $encryptionProfileManager;

public function __construct(ConfigFactoryInterface $config_factory, EncryptionProfileManager $encryptionProfileManager)
{
parent::__construct($config_factory);
$this->encryptionProfileManager = $encryptionProfileManager;
}

public static function create(ContainerInterface $container)
{
return new static(
$container->get('config.factory'),
$container->get('encrypt.encryption_profile.manager')
);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -58,9 +82,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#default_value' => $config->get('enabled'),
];

// TODO: RESOLVE WITH DEPENDENCY INJECTION
$encryptionOptions = \Drupal::service('encrypt.encryption_profile.manager')
->getEncryptionProfileNamesAsOptions();
$encryptionOptions = $this->encryptionProfileManager->getEncryptionProfileNamesAsOptions();

$form['default_encryption_profile'] = [
'#type' => 'select',
Expand Down
2 changes: 1 addition & 1 deletion modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Os2FormsEncryptor {
/**
* The config factory.
*
* @var ConfigFactoryInterface
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
private ConfigFactoryInterface $configFactory;

Expand Down

0 comments on commit 9b1e54e

Please sign in to comment.