diff --git a/modules/os2forms_encrypt/os2forms_encrypt.services.yml b/modules/os2forms_encrypt/os2forms_encrypt.services.yml index 04eb939..3d474c7 100644 --- a/modules/os2forms_encrypt/os2forms_encrypt.services.yml +++ b/modules/os2forms_encrypt/os2forms_encrypt.services.yml @@ -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'] diff --git a/modules/os2forms_encrypt/src/Form/SettingsForm.php b/modules/os2forms_encrypt/src/Form/SettingsForm.php index 0f3f086..4b6edcb 100644 --- a/modules/os2forms_encrypt/src/Form/SettingsForm.php +++ b/modules/os2forms_encrypt/src/Form/SettingsForm.php @@ -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. @@ -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} */ @@ -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', diff --git a/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php b/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php index 29048f0..3dc5df9 100644 --- a/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php +++ b/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php @@ -32,7 +32,7 @@ class Os2FormsEncryptor { /** * The config factory. * - * @var ConfigFactoryInterface + * @var \Drupal\Core\Config\ConfigFactoryInterface */ private ConfigFactoryInterface $configFactory;