diff --git a/CHANGELOG.md b/CHANGELOG.md index e849be68..d6fbf37f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#101](https://github.com/OS2Forms/os2forms/pull/101) - Added support for `os2web_key` in Digital post + - Switched from saving settings in key value store to config, i.e + the module needs to be reconfigured. - Added support for `os2web_key` in Fasit handler. - Switched from saving settings in key value store to config, i.e the module needs to be reconfigured. diff --git a/composer.json b/composer.json index aee475b2..7972ad98 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ "itk-dev/serviceplatformen": "^1.5", "mglaman/composer-drupal-lenient": "^1.0", "os2web/os2web_audit": "^0.1.6", - "os2web/os2web_datalookup": "dev-feature/os2web_key as 2.0.0", + "os2web/os2web_datalookup": "^2.0", "os2web/os2web_key": "^1.0", "os2web/os2web_nemlogin": "^1.0", "os2web/os2web_simplesaml": "dev-master", @@ -81,10 +81,6 @@ "wsdltophp/packagegenerator": "^4.0" }, "repositories": { - "os2web/os2web_datalookup": { - "type": "vcs", - "url": "https://github.com/itk-dev/os2web_datalookup" - }, "drupal": { "type": "composer", "url": "https://packages.drupal.org/8" diff --git a/modules/os2forms_digital_post/drush.services.yml b/modules/os2forms_digital_post/drush.services.yml deleted file mode 100644 index 7339bc2a..00000000 --- a/modules/os2forms_digital_post/drush.services.yml +++ /dev/null @@ -1,10 +0,0 @@ -services: - os2forms_digital_post.commands: - class: \Drupal\os2forms_digital_post\Commands\DigitalPostTestCommands - arguments: - - '@Drupal\os2forms_digital_post\Helper\DigitalPostHelper' - - '@token' - - '@plugin.manager.entity_print.print_engine' - - '@Drupal\os2forms_digital_post\Helper\Settings' - tags: - - { name: drush.command } diff --git a/modules/os2forms_digital_post/os2forms_digital_post.services.yml b/modules/os2forms_digital_post/os2forms_digital_post.services.yml index 9b096fad..1b554d91 100644 --- a/modules/os2forms_digital_post/os2forms_digital_post.services.yml +++ b/modules/os2forms_digital_post/os2forms_digital_post.services.yml @@ -8,64 +8,29 @@ services: arguments: [ 'webform_submission' ] Drupal\os2forms_digital_post\Helper\Settings: - arguments: - - "@config.factory" - - "@key.repository" + autowire: true Drupal\os2forms_digital_post\Helper\CertificateLocatorHelper: - arguments: - - "@Drupal\\os2forms_digital_post\\Helper\\Settings" - - "@key.repository" + autowire: true Drupal\os2forms_digital_post\Helper\MeMoHelper: - arguments: - - "@Drupal\\os2forms_digital_post\\Helper\\Settings" - - "@plugin.manager.element_info" - - "@webform.token_manager" + autowire: true Drupal\os2forms_digital_post\Helper\ForsendelseHelper: - arguments: - - "@Drupal\\os2forms_digital_post\\Helper\\Settings" - - "@plugin.manager.element_info" - - "@webform.token_manager" + autowire: true Drupal\os2forms_digital_post\Helper\DigitalPostHelper: - arguments: - - "@Drupal\\os2forms_digital_post\\Helper\\Settings" - - "@Drupal\\os2web_key\\KeyHelper" - - "@plugin.manager.os2web_datalookup" - - "@Drupal\\os2forms_digital_post\\Helper\\MeMoHelper" - - "@Drupal\\os2forms_digital_post\\Helper\\ForsendelseHelper" - - "@Drupal\\os2forms_digital_post\\Helper\\BeskedfordelerHelper" - - "@logger.channel.os2forms_digital_post" - - "@logger.channel.os2forms_digital_post_submission" - - "@os2web_audit.logger" + autowire: true Drupal\os2forms_digital_post\Helper\WebformHelperSF1601: - arguments: - - "@Drupal\\os2forms_digital_post\\Helper\\Settings" - - "@entity_type.manager" - - "@plugin.manager.os2web_datalookup" - - "@Drupal\\os2forms_digital_post\\Helper\\MeMoHelper" - - "@Drupal\\os2forms_digital_post\\Helper\\ForsendelseHelper" - - "@Drupal\\os2forms_digital_post\\Helper\\BeskedfordelerHelper" - - "@logger.channel.os2forms_digital_post" - - "@logger.channel.os2forms_digital_post_submission" - - "@Drupal\\os2forms_digital_post\\Helper\\DigitalPostHelper" + autowire: true Drupal\os2forms_digital_post\Helper\SF1461Helper: Drupal\os2forms_digital_post\EventSubscriber\BeskedfordelerEventSubscriber: - arguments: - - '@Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper' - - '@Drupal\beskedfordeler\Helper\MessageHelper' - - '@Drupal\os2forms_digital_post\Helper\WebformHelperSF1601' - - '@logger.channel.os2forms_digital_post' + autowire: true tags: - { name: 'event_subscriber' } Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper: - arguments: - - '@database' - - '@Drupal\os2forms_digital_post\Helper\MeMoHelper' - - '@logger.channel.os2forms_digital_post' + autowire: true diff --git a/modules/os2forms_digital_post/src/Commands/DigitalPostTestCommands.php b/modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php similarity index 94% rename from modules/os2forms_digital_post/src/Commands/DigitalPostTestCommands.php rename to modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php index 5e9bdbbf..6b23d874 100644 --- a/modules/os2forms_digital_post/src/Commands/DigitalPostTestCommands.php +++ b/modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php @@ -1,8 +1,9 @@ 'fieldset', '#title' => $this->t('Certificate'), '#tree' => TRUE, + ]; + + $form[Settings::CERTIFICATE][Settings::CERTIFICATE_PROVIDER] = [ + '#type' => 'select', + '#title' => $this->t('Provider'), + '#options' => [ + Settings::PROVIDER_TYPE_FORM => $this->t('Form'), + Settings::PROVIDER_TYPE_KEY => $this->t('Key'), + ], + '#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::CERTIFICATE_PROVIDER]) ?? Settings::PROVIDER_TYPE_FORM, + '#description' => $this->t('Specifies which provider to use'), + ]; + + $form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE] = [ + '#type' => 'select', + '#title' => $this->t('Certificate locator type'), + '#options' => [ + CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT => $this->t('Azure key vault'), + CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM => $this->t('File system'), + ], + '#default_value' => $this->settings->getEditableValue([ + Settings::CERTIFICATE, + CertificateLocatorHelper::LOCATOR_TYPE, + ]) ?? NULL, + '#states' => [ + 'visible' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM]], + ], + '#description' => $this->t('Specifies which locator to use'), + ]; - Settings::KEY => [ - '#type' => 'key_select', - '#key_filters' => [ - 'type' => 'os2web_key_certificate', + $form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT] = [ + '#type' => 'fieldset', + '#title' => $this->t('Azure key vault'), + '#states' => [ + 'visible' => [ + ':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM], + ':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT], + ], + ], + ]; + + $settings = [ + CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_TENANT_ID => ['title' => $this->t('Tenant id')], + CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_APPLICATION_ID => ['title' => $this->t('Application id')], + CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_CLIENT_SECRET => ['title' => $this->t('Client secret')], + CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_NAME => ['title' => $this->t('Name')], + CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_SECRET => ['title' => $this->t('Secret')], + CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_VERSION => ['title' => $this->t('Version')], + ]; + + foreach ($settings as $key => $info) { + $form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT][$key] = [ + '#type' => 'textfield', + '#title' => $info['title'], + '#default_value' => $this->settings->getEditableValue([ + Settings::CERTIFICATE, + CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT, + $key, + ]) ?? NULL, + '#states' => [ + 'required' => [ + ':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM], + ':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT], + ], + ], + ]; + } + + $form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM] = [ + '#type' => 'fieldset', + '#title' => $this->t('File system'), + '#states' => [ + 'visible' => [ + ':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM], + ':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM], ], - '#key_description' => FALSE, - '#title' => $this->t('Key'), - '#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::KEY]), - '#required' => TRUE, - '#description' => $this->createDescription([Settings::CERTIFICATE, Settings::KEY]), + ], + + CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH => [ + '#type' => 'textfield', + '#title' => $this->t('Path'), + '#default_value' => $this->settings->getEditableValue([ + Settings::CERTIFICATE, + CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM, + CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH, + ]) ?? NULL, + '#states' => [ + 'required' => [ + ':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM], + ':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM], + ], + ], + ], + ]; + + $form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_PASSPHRASE] = [ + '#type' => 'textfield', + '#title' => $this->t('Passphrase'), + '#default_value' => $this->settings->getEditableValue([ + Settings::CERTIFICATE, + CertificateLocatorHelper::LOCATOR_PASSPHRASE, + ]) ?? '', + '#states' => [ + 'visible' => [ + ':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM], + ], + ], + ]; + + $form[Settings::CERTIFICATE][Settings::PROVIDER_TYPE_KEY] = [ + '#type' => 'key_select', + '#key_filters' => [ + 'type' => 'os2web_key_certificate', + ], + '#key_description' => FALSE, + '#title' => $this->t('Key'), + '#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::PROVIDER_TYPE_KEY]), + '#description' => $this->createDescription([Settings::CERTIFICATE, Settings::PROVIDER_TYPE_KEY]), + '#states' => [ + 'visible' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_KEY]], + 'required' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_KEY]], ], ]; @@ -179,6 +290,26 @@ public function buildForm(array $form, FormStateInterface $form_state): array { return $form; } + /** + * {@inheritdoc} + * + * @phpstan-param array $form + */ + public function validateForm(array &$form, FormStateInterface $form_state): void { + $values = $form_state->getValues(); + + if (Settings::PROVIDER_TYPE_FORM === $values[Settings::CERTIFICATE][Settings::CERTIFICATE_PROVIDER]) { + if (CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM === $values[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE]) { + $path = $values[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM][CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH] ?? NULL; + if (!file_exists($path)) { + $form_state->setErrorByName('certificate][file_system][path', $this->t('Invalid certificate path: %path', ['%path' => $path])); + } + } + } + + parent::validateForm($form, $form_state); + } + /** * {@inheritdoc} * diff --git a/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php b/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php index d9fb96a3..e4a85abb 100644 --- a/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php +++ b/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php @@ -12,6 +12,7 @@ use Drupal\webform_attachment\Element\WebformAttachmentBase; use ItkDev\Serviceplatformen\Service\SF1601\Serializer; use Oio\Fjernprint\ForsendelseI; +use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Abstract message helper. @@ -23,6 +24,7 @@ abstract class AbstractMessageHelper { */ public function __construct( readonly protected Settings $settings, + #[Autowire(service: 'plugin.manager.element_info')] readonly protected ElementInfoManager $elementInfoManager, readonly protected WebformTokenManagerInterface $webformTokenManager, ) { diff --git a/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php b/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php index 5b93da5e..c256dc17 100644 --- a/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php +++ b/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php @@ -9,6 +9,7 @@ use Drupal\webform\WebformSubmissionInterface; use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Beskedfordeler helper. @@ -24,6 +25,7 @@ class BeskedfordelerHelper { public function __construct( private readonly Connection $database, private readonly MeMoHelper $meMoHelper, + #[Autowire(service: 'logger.channel.os2forms_digital_post')] LoggerInterface $logger, ) { $this->setLogger($logger); diff --git a/modules/os2forms_digital_post/src/Helper/CertificateLocatorHelper.php b/modules/os2forms_digital_post/src/Helper/CertificateLocatorHelper.php new file mode 100644 index 00000000..01fde400 --- /dev/null +++ b/modules/os2forms_digital_post/src/Helper/CertificateLocatorHelper.php @@ -0,0 +1,88 @@ +settings->getEditableValue(Settings::CERTIFICATE); + + $locatorType = $certificateSettings['locator_type']; + $options = $certificateSettings[$locatorType]; + $options += [ + 'passphrase' => $certificateSettings['passphrase'], + ]; + + if (self::LOCATOR_TYPE_AZURE_KEY_VAULT === $locatorType) { + $httpClient = new GuzzleAdapter(new Client()); + $requestFactory = new RequestFactory(); + + $vaultToken = new VaultToken($httpClient, $requestFactory); + + $token = $vaultToken->getToken( + $options['tenant_id'], + $options['application_id'], + $options['client_secret'], + ); + + $vault = new VaultSecret( + $httpClient, + $requestFactory, + $options['name'], + $token->getAccessToken() + ); + + return new AzureKeyVaultCertificateLocator( + $vault, + $options['secret'], + $options['version'], + $options['passphrase'], + ); + } + elseif (self::LOCATOR_TYPE_FILE_SYSTEM === $locatorType) { + $certificatepath = realpath($options['path']) ?: NULL; + if (NULL === $certificatepath) { + throw new CertificateLocatorException(sprintf('Invalid certificate path %s', $options['path'])); + } + return new FilesystemCertificateLocator($certificatepath, $options['passphrase']); + } + + throw new CertificateLocatorException(sprintf('Invalid certificate locator type: %s', $locatorType)); + } + +} diff --git a/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php b/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php index 80825dff..44198074 100644 --- a/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php +++ b/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php @@ -18,6 +18,7 @@ use Oio\Fjernprint\ForsendelseI; use Psr\Log\LoggerInterface; use Psr\Log\LoggerTrait; +use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Webform helper. @@ -31,12 +32,17 @@ final class DigitalPostHelper implements LoggerInterface { public function __construct( private readonly Settings $settings, private readonly KeyHelper $keyHelper, + #[Autowire(service: 'plugin.manager.os2web_datalookup')] private readonly DataLookupManager $dataLookupManager, private readonly MeMoHelper $meMoHelper, private readonly ForsendelseHelper $forsendelseHelper, private readonly BeskedfordelerHelper $beskedfordelerHelper, + private readonly CertificateLocatorHelper $certificateLocatorHelper, + #[Autowire(service: 'logger.channel.os2forms_digital_post')] private readonly LoggerChannelInterface $logger, + #[Autowire(service: 'logger.channel.os2forms_digital_post_submission')] private readonly LoggerChannelInterface $submissionLogger, + #[Autowire(service: 'os2web_audit.logger')] private readonly Logger $auditLogger, ) { } @@ -60,14 +66,23 @@ public function __construct( */ public function sendDigitalPost(string $type, Message $message, ?ForsendelseI $forsendelse, ?WebformSubmissionInterface $submission = NULL): array { $senderSettings = $this->settings->getSender(); + + if (Settings::PROVIDER_TYPE_FORM === $this->settings->getCertificateProvider()) { + $certificateLocator = $this->certificateLocatorHelper->getCertificateLocator(); + } + else { + $certificateLocator = new KeyCertificateLocator( + $this->settings->getCertificateKey(), + $this->keyHelper + ); + } + $options = [ 'test_mode' => (bool) $this->settings->getTestMode(), 'authority_cvr' => $senderSettings[Settings::SENDER_IDENTIFIER], - 'certificate_locator' => new KeyCertificateLocator( - $this->settings->getCertificateKey(), - $this->keyHelper - ), + 'certificate_locator' => $certificateLocator, ]; + $service = new SF1601($options); $transactionId = Serializer::createUuid(); diff --git a/modules/os2forms_digital_post/src/Helper/Settings.php b/modules/os2forms_digital_post/src/Helper/Settings.php index c0d5384d..fc7ab385 100644 --- a/modules/os2forms_digital_post/src/Helper/Settings.php +++ b/modules/os2forms_digital_post/src/Helper/Settings.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\ImmutableConfig; use Drupal\key\KeyInterface; use Drupal\key\KeyRepositoryInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * General settings for os2forms_digital_post. @@ -23,6 +24,9 @@ final class Settings { public const CERTIFICATE = 'certificate'; public const KEY = 'key'; + public const CERTIFICATE_PROVIDER = 'certificate_provider'; + public const PROVIDER_TYPE_FORM = 'form'; + public const PROVIDER_TYPE_KEY = 'key'; public const PROCESSING = 'processing'; public const QUEUE = 'queue'; @@ -46,6 +50,7 @@ final class Settings { */ public function __construct( ConfigFactoryInterface $configFactory, + #[Autowire(service: 'key.repository')] private readonly KeyRepositoryInterface $keyRepository, ) { $this->runtimeConfig = $configFactory->get(self::CONFIG_NAME); @@ -70,6 +75,13 @@ public function getSender(): array { return is_array($value) ? $value : []; } + /** + * Get certificate provider. + */ + public function getCertificateProvider(): ?string { + return $this->get([self::CERTIFICATE, self::CERTIFICATE_PROVIDER]); + } + /** * Get key. */ diff --git a/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php b/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php index 3c2c724e..60fae6a2 100644 --- a/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php +++ b/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php @@ -21,6 +21,7 @@ use ItkDev\Serviceplatformen\Service\SF1601\SF1601; use Psr\Log\LoggerInterface; use Psr\Log\LoggerTrait; +use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Webform helper. @@ -51,11 +52,14 @@ final class WebformHelperSF1601 implements LoggerInterface { public function __construct( private readonly Settings $settings, EntityTypeManagerInterface $entityTypeManager, + #[Autowire(service: 'plugin.manager.os2web_datalookup')] private readonly DataLookupManager $dataLookupManager, private readonly MeMoHelper $meMoHelper, private readonly ForsendelseHelper $forsendelseHelper, private readonly BeskedfordelerHelper $beskedfordelerHelper, + #[Autowire(service: 'logger.channel.os2forms_digital_post')] private readonly LoggerChannelInterface $logger, + #[Autowire(service: 'logger.channel.os2forms_digital_post_submission')] private readonly LoggerChannelInterface $submissionLogger, private readonly DigitalPostHelper $digitalPostHelper, ) { diff --git a/modules/os2forms_fasit/src/Drush/Commands/FasitTestCommand.php b/modules/os2forms_fasit/src/Drush/Commands/FasitTestCommand.php index 586adc04..9d1fb281 100644 --- a/modules/os2forms_fasit/src/Drush/Commands/FasitTestCommand.php +++ b/modules/os2forms_fasit/src/Drush/Commands/FasitTestCommand.php @@ -2,14 +2,15 @@ namespace Drupal\os2forms_fasit\Drush\Commands; +use Drupal\Core\DependencyInjection\AutowireTrait; use Drupal\os2forms_fasit\Helper\FasitHelper; use Drush\Commands\DrushCommands; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * A Drush commandfile. */ final class FasitTestCommand extends DrushCommands { + use AutowireTrait; /** * Constructs a FasitTestCommand object. @@ -20,15 +21,6 @@ public function __construct( parent::__construct(); } - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get(FasitHelper::class), - ); - } - /** * Test API access. * diff --git a/modules/os2forms_fasit/src/Form/SettingsForm.php b/modules/os2forms_fasit/src/Form/SettingsForm.php index fdd6e0e0..9e05b95b 100644 --- a/modules/os2forms_fasit/src/Form/SettingsForm.php +++ b/modules/os2forms_fasit/src/Form/SettingsForm.php @@ -209,10 +209,10 @@ public function buildForm(array $form, FormStateInterface $form_state): array { 'type' => 'os2web_key_certificate', ], '#title' => $this->t('Key'), - '#required' => TRUE, - '#default_value' => $config->get(self::PROVIDER_TYPE_KEY), + '#default_value' => $certificateConfig[self::PROVIDER_TYPE_KEY] ?? NULL, '#states' => [ 'visible' => [':input[name="certificate[certificate_provider]"]' => ['value' => self::PROVIDER_TYPE_KEY]], + 'required' => [':input[name="certificate[certificate_provider]"]' => ['value' => self::PROVIDER_TYPE_KEY]], ], ]; diff --git a/modules/os2forms_fasit/src/Helper/Settings.php b/modules/os2forms_fasit/src/Helper/Settings.php index 09d0cd92..09410299 100644 --- a/modules/os2forms_fasit/src/Helper/Settings.php +++ b/modules/os2forms_fasit/src/Helper/Settings.php @@ -78,7 +78,9 @@ public function getFasitCertificateLocator(): string { * Get Fasit key certificate configuration. */ public function getFasitCertificateKey(): ?string { - return $this->get(SettingsForm::KEY); + $config = $this->getFasitCertificateConfig(); + + return $config[SettingsForm::PROVIDER_TYPE_KEY] ?? NULL; } /**