From 26644f4b9decd8a361824aca80271e03961e7a70 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 15 Feb 2024 13:07:31 +0100 Subject: [PATCH 1/3] Added FBS webform handler module --- CHANGELOG.md | 2 + composer.json | 1 + ...vancedqueue_queue.os2forms_fbs_handler.yml | 10 + .../os2forms_fbs_handler.info.yml | 9 + .../os2forms_fbs_handler/src/Client/FBS.php | 234 ++++++++++++++++++ .../src/Client/Model/Guardian.php | 34 +++ .../src/Client/Model/Patron.php | 52 ++++ .../AdvancedQueue/JobType/FbsCreateUser.php | 140 +++++++++++ .../WebformHandler/FbsWebformHandler.php | 212 ++++++++++++++++ 9 files changed, 694 insertions(+) create mode 100644 modules/os2forms_fbs_handler/config/install/advancedqueue.advancedqueue_queue.os2forms_fbs_handler.yml create mode 100644 modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml create mode 100644 modules/os2forms_fbs_handler/src/Client/FBS.php create mode 100644 modules/os2forms_fbs_handler/src/Client/Model/Guardian.php create mode 100644 modules/os2forms_fbs_handler/src/Client/Model/Patron.php create mode 100644 modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php create mode 100644 modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e1764f85..8c980d97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] - Adding Lat and Long fetching to DataAddress +- CprFetchData adding ajax error fix - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. +- Added FBS handler for supporting user creation in library systems ## [3.14.1] 2024-01-16 diff --git a/composer.json b/composer.json index 50d3d8f6..9e4b38da 100644 --- a/composer.json +++ b/composer.json @@ -71,6 +71,7 @@ "drupal/webform_validation": "^2.0", "drupal/webform_views": "^5.0@alpha", "drupal/workflow_participants": "^2.4", + "fig/http-message-util": "^1.1", "http-interop/http-factory-guzzle": "^1.0.0", "itk-dev/beskedfordeler-drupal": "^1.0", "itk-dev/serviceplatformen": "dev-feature/guzzle6-adapter as 1.5", diff --git a/modules/os2forms_fbs_handler/config/install/advancedqueue.advancedqueue_queue.os2forms_fbs_handler.yml b/modules/os2forms_fbs_handler/config/install/advancedqueue.advancedqueue_queue.os2forms_fbs_handler.yml new file mode 100644 index 00000000..01b469d7 --- /dev/null +++ b/modules/os2forms_fbs_handler/config/install/advancedqueue.advancedqueue_queue.os2forms_fbs_handler.yml @@ -0,0 +1,10 @@ +status: true +dependencies: { } +id: os2forms_fbs_handler +label: os2forms_fbs_handler +backend: database +backend_configuration: + lease_time: 300 +processor: cron +processing_time: 90 +locked: false diff --git a/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml new file mode 100644 index 00000000..d2a16222 --- /dev/null +++ b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml @@ -0,0 +1,9 @@ +name: 'FBS Handler' +type: module +description: 'Provides integration to FBS.' +package: 'OS2Forms' +core: 8.x +core_version_requirement: ^8 || ^9 +dependencies: + - 'webform:webform' + - 'advancedqueue:advancedqueue' diff --git a/modules/os2forms_fbs_handler/src/Client/FBS.php b/modules/os2forms_fbs_handler/src/Client/FBS.php new file mode 100644 index 00000000..f628ee87 --- /dev/null +++ b/modules/os2forms_fbs_handler/src/Client/FBS.php @@ -0,0 +1,234 @@ + $this->username, + 'password' => $this->password, + ]; + + $json = $this->request($uri, $payload); + if (isset($json->sessionKey)) { + $this->sessionKey = $json->sessionKey; + + return TRUE; + } + + return FALSE; + } + + /** + * Check is user is logged in. + * + * @return bool + * TRUE if logged in else FALSE. + */ + public function isLoggedIn(): bool { + return isset($this->sessionKey); + } + + /** + * Check if user exists. + * + * @param string $cpr + * The users personal security number. + * + * @return \Drupal\os2forms_fbs_handler\Client\Model\Patron|null + * NULL if not else the Patron. + * + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \JsonException + */ + public function doUserExists(string $cpr): ?Patron { + // Check if session have been created with FBS and if not create it. + if (!$this->isLoggedIn()) { + $this->login(); + } + + // Try pre-authenticate the user/parent. + $json = $this->request('/external/{agency_id}/patrons/preauthenticated/v9', $cpr); + if ($json->authenticateStatus === 'VALID') { + return new Patron( + $json->patron->patronId, + (bool) $json->patron->receiveSms, + (bool) $json->patron->receivePostalMail, + $json->patron->notificationProtocols, + $json->patron->phoneNumber, + is_null($json->patron->onHold) ? $json->patron->onHold : (array) $json->patron->onHold, + $json->patron->preferredLanguage, + (bool) $json->patron->guardianVisibility, + $json->patron->emailAddress, + (bool) $json->patron->receiveEmail, + $json->patron->preferredPickupBranch + ); + } + + return NULL; + } + + /** + * Create new patron with guardian attached. + * + * @param \Drupal\os2forms_fbs_handler\Client\Model\Patron $patron + * The patron to create. + * @param \Drupal\os2forms_fbs_handler\Client\Model\Guardian $guardian + * The guardian to attach to the parton. + * + * @return mixed + * JSON response from FBS. + * + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \JsonException + */ + public function createPatronWithGuardian(Patron $patron, Guardian $guardian) { + $uri = '/external/{agency_id}/patrons/withGuardian/v1'; + $payload = [ + 'cprNumber' => $patron->cpr, + 'pincode' => $patron->pincode, + 'preferredPickupBranch' => $patron->preferredPickupBranch, + 'name' => 'Unknown Name', + 'email' => $patron->emailAddress, + 'guardian' => $guardian->toArray(), + ]; + + return $this->request($uri, $payload,); + } + + /** + * Update patron information. + * + * @param \Drupal\os2forms_fbs_handler\Client\Model\Patron $patron + * The patron to update. + * + * @return bool + * TRUE if success else FALSE. + * + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \JsonException + */ + public function updatePatron(Patron $patron): bool { + $uri = '/external/{agency_id}/patrons/' . $patron->patronId . '/v6'; + $payload = [ + 'patronid' => $patron->patronId, + 'patron' => $patron->toArray(), + 'pincodeChange' => [ + 'pincode' => $patron->pincode, + 'libraryCardNumber' => $patron->cpr, + ], + ]; + + $json = $this->request($uri, $payload, RequestMethodInterface::METHOD_PUT); + + return $json->authenticateStatus === 'VALID'; + } + + /** + * Create guardian for patron. + * + * @param \Drupal\os2forms_fbs_handler\Client\Model\Patron $patron + * Patron to create guardian for. + * @param \Drupal\os2forms_fbs_handler\Client\Model\Guardian $guardian + * The guardian to create. + * + * @return int + * Guardian identifier. + * + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \JsonException + */ + public function createGuardian(Patron $patron, Guardian $guardian): int { + $uri = '/external/{agency_id}/patrons/withGuardian/v1'; + $payload = [ + 'patronId' => $patron->patronId, + 'guardian' => $guardian->toArray(), + ]; + + return $this->request($uri, $payload, RequestMethodInterface::METHOD_PUT); + } + + /** + * Send request to FSB. + * + * @param string $uri + * The uri/path to send request to. + * @param array|string $data + * The json or string to send to FBS. + * @param string $method + * The type of request to send (Default: POST). + * + * @return mixed + * Json response from FBS. + * + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \JsonException + */ + private function request(string $uri, array|string $data, string $method = RequestMethodInterface::METHOD_POST): mixed { + $url = rtrim($this->endpoint, '/\\'); + $url = $url . str_replace('{agency_id}', $this->agencyId, $uri); + + $options = [ + 'headers' => [ + 'Content-type' => 'application/json; charset=utf-8', + ], + ]; + + // The API designer at FBS don't always use JSON. So in some cases only a + // string should be sent. + if (is_array($data)) { + $options['json'] = $data; + } + else { + $options['body'] = $data; + } + + // If already logged in lets add the session key to the request headers. + if ($this->isLoggedIn()) { + $options['headers']['X-Session'] = $this->sessionKey; + } + + $response = $this->client->request($method, $url, $options); + + return json_decode($response->getBody(), FALSE, 512, JSON_THROW_ON_ERROR); + } + +} diff --git a/modules/os2forms_fbs_handler/src/Client/Model/Guardian.php b/modules/os2forms_fbs_handler/src/Client/Model/Guardian.php new file mode 100644 index 00000000..150db93e --- /dev/null +++ b/modules/os2forms_fbs_handler/src/Client/Model/Guardian.php @@ -0,0 +1,34 @@ + $this->cpr, + 'name' => $this->name, + 'email' => $this->email, + ]; + } + +} diff --git a/modules/os2forms_fbs_handler/src/Client/Model/Patron.php b/modules/os2forms_fbs_handler/src/Client/Model/Patron.php new file mode 100644 index 00000000..4847c944 --- /dev/null +++ b/modules/os2forms_fbs_handler/src/Client/Model/Patron.php @@ -0,0 +1,52 @@ + $this->receiveEmail, + 'receiveSms' => $this->receiveSms, + 'receivePostalMail' => $this->receivePostalMail, + 'emailAddress' => $this->emailAddress, + 'notificationProtocols' => $this->notificationProtocols, + 'phoneNumber' => $this->phoneNumber, + 'preferredPickupBranch' => $this->preferredPickupBranch, + 'onHold' => $this->onHold, + 'preferredLanguage' => $this->preferredLanguage, + 'guardianVisibility' => $this->guardianVisibility, + ]; + } + +} diff --git a/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php b/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php new file mode 100644 index 00000000..2ed0908c --- /dev/null +++ b/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php @@ -0,0 +1,140 @@ +submissionLogger = $loggerFactory->get('webform_submission'); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('logger.factory'), + $container->get('http_client') + ); + } + + /** + * {@inheritdoc} + */ + public function process(Job $job): JobResult { + try { + $payload = $job->getPayload(); + + /** @var \Drupal\webform\WebformSubmissionInterface $webformSubmission */ + $webformSubmission = WebformSubmission::load($payload['submissionId']); + $logger_context = [ + 'handler_id' => 'os2forms_fbs', + 'channel' => 'webform_submission', + 'webform_submission' => $webformSubmission, + 'operation' => 'response from queue', + ]; + $config = $payload['configuration']; + + try { + $fbs = new FBS($this->client, $config['endpoint_url'], $config['agency_id'], $config['username'], $config['password']); + + // Log into FBS and obtain session. + $fbs->login(); + + $data = $webformSubmission->getData(); + + // Checker child patron exists. + $patron = $fbs->doUserExists($data['barn_cpr']); + + // Create Guardian. + $guardian = new Guardian( + $data['cpr'], + $data['navn'], + $data['email'] + ); + + // If "yes" update the child patron and create the guardian (the + // guardian is not another patron user). + if (!is_null($patron)) { + // Create Patron object with updated values. + $patron->preferredPickupBranch = $data['afhentningssted']; + $patron->emailAddress = $data['barn_mail']; + $patron->receiveEmail = TRUE; + $patron->cpr = $data['barn_cpr']; + $patron->pincode = $data['pinkode']; + + $fbs->updatePatron($patron); + $fbs->createGuardian($patron, $guardian); + } + else { + // If "no" create child patron and guardian. + $patron = new Patron(); + $patron->preferredPickupBranch = $data['afhentningssted']; + $patron->emailAddress = $data['barn_mail']; + $patron->receiveEmail = TRUE; + $patron->cpr = $data['barn_cpr']; + $patron->pincode = $data['pinkode']; + + $fbs->createPatronWithGuardian($patron, $guardian); + } + + $this->submissionLogger->notice($this->t('The submission #@serial was successfully delivered', ['@serial' => $webformSubmission->serial()]), $logger_context); + + return JobResult::success(); + } + catch (\Exception | GuzzleException $e) { + $this->submissionLogger->error($this->t('The submission #@serial failed (@message)', [ + '@serial' => $webformSubmission->serial(), + '@message' => $e->getMessage(), + ]), $logger_context); + + return JobResult::failure($e->getMessage()); + } + } + catch (\Exception $e) { + return JobResult::failure($e->getMessage()); + } + } + +} diff --git a/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php new file mode 100644 index 00000000..e201d2d0 --- /dev/null +++ b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php @@ -0,0 +1,212 @@ +setConfiguration($configuration); + $this->loggerFactory = $loggerFactory; + $this->configFactory = $configFactory; + $this->renderer = $renderer; + $this->entityTypeManager = $entityTypeManager; + $this->conditionsValidator = $conditionsValidator; + $this->tokenManager = $tokenManager; + $this->submissionLogger = $loggerFactory->get('webform_submission'); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('logger.factory'), + $container->get('config.factory'), + $container->get('renderer'), + $container->get('entity_type.manager'), + $container->get('webform_submission.conditions_validator'), + $container->get('webform.token_manager') + ); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { + if (is_null($this->getQueue())) { + $form['queue_message'] = [ + '#theme' => 'status_messages', + '#message_list' => [ + 'warning' => [$this->t('Cannot get queue @queue_id', ['@queue_id' => $this->queueId])], + ], + ]; + } + + $translation_options = ['context' => 'FBS configuration']; + + $form['wrapper'] = [ + '#type' => 'fieldset', + '#title' => $this->t('FBS configuration', [], $translation_options), + '#tree' => TRUE, + ]; + + $form['wrapper']['agency_id'] = [ + '#type' => 'textfield', + '#title' => $this->t('ISIL', [], $translation_options), + '#description' => $this->t('The library\'s ISIL number (e.g. "DK-775100" for Aarhus libraries', [], $translation_options), + '#required' => TRUE, + '#default_value' => $this->configuration['agency_id'] ?? '', + ]; + + $form['wrapper']['endpoint_url'] = [ + '#type' => 'url', + '#title' => $this->t('FBS endpoint URL', [], $translation_options), + '#description' => $this->t('The URL for the FBS REST service, usually something like https://et.cicero-fbs.com/rest'), + '#required' => TRUE, + '#default_value' => $this->configuration['endpoint_url'] ?? 'https://cicero-fbs.com/rest/', + ]; + + $form['wrapper']['username'] = [ + '#type' => 'textfield', + '#title' => $this->t('Username', [], $translation_options), + '#description' => $this->t('FBS username to allow connection to FBS'), + '#required' => TRUE, + '#default_value' => $this->configuration['username'] ?? '', + ]; + + $form['wrapper']['password'] = [ + '#type' => 'password', + '#title' => $this->t('Password', [], $translation_options), + '#description' => $this->t('Password to access the API'), + '#required' => TRUE, + '#default_value' => $this->configuration['password'] ?? '', + ]; + + return $this->setSettingsParents($form); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { + parent::submitConfigurationForm($form, $form_state); + $this->configuration['agency_id'] = $form_state + ->getValue(['wrapper', 'agency_id']); + $this->configuration['endpoint_url'] = $form_state + ->getValue(['wrapper', 'endpoint_url']); + $this->configuration['username'] = $form_state + ->getValue(['wrapper', 'username']); + $this->configuration['password'] = $form_state + ->getValue(['wrapper', 'password']); + } + + /** + * {@inheritdoc} + */ + public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE): void { + $logger_context = [ + 'handler_id' => 'os2forms_fbs', + 'channel' => 'webform_submission', + 'webform_submission' => $webform_submission, + 'operation' => 'submission queued', + ]; + + // Validate fields required in the job and FBS client. + $data = $webform_submission->getData(); + $fields = [ + 'afhentningssted', + 'barn_cpr', + 'barn_mail', + 'cpr', + 'email', + 'navn', + 'pinkode', + ]; + foreach ($fields as $field) { + if (!isset($data[$field])) { + $this->submissionLogger->error($this->t('Missing field in submission @field to queue for processing', ['@field' => $field]), $logger_context); + return; + } + } + + /** @var \Drupal\advancedqueue\Entity\Queue $queue */ + $queue = $this->getQueue(); + $job = Job::create(FbsCreateUser::class, [ + 'submissionId' => $webform_submission->id(), + 'configuration' => $this->configuration, + ]); + $queue->enqueueJob($job); + + $this->submissionLogger->notice($this->t('Added submission #@serial to queue for processing', ['@serial' => $webform_submission->serial()]), $logger_context); + } + + /** + * Get queue. + */ + private function getQueue(): ?Queue { + $queueStorage = $this->entityTypeManager->getStorage('advancedqueue_queue'); + /** @var ?\Drupal\advancedqueue\Entity\Queue $queue */ + $queue = $queueStorage->load($this->queueId); + + return $queue; + } + +} From 937b86d1a3533f0fb6ca95e1077b5ff782676dd4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2024 11:14:11 +0100 Subject: [PATCH 2/3] Updated code style after review in FBS handler --- composer.json | 1 - .../os2forms_fbs_handler.info.yml | 3 +-- .../os2forms_fbs_handler/src/Client/FBS.php | 24 ++++++++++--------- .../WebformHandler/FbsWebformHandler.php | 8 +++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 9e4b38da..50d3d8f6 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,6 @@ "drupal/webform_validation": "^2.0", "drupal/webform_views": "^5.0@alpha", "drupal/workflow_participants": "^2.4", - "fig/http-message-util": "^1.1", "http-interop/http-factory-guzzle": "^1.0.0", "itk-dev/beskedfordeler-drupal": "^1.0", "itk-dev/serviceplatformen": "dev-feature/guzzle6-adapter as 1.5", diff --git a/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml index d2a16222..53bba305 100644 --- a/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml +++ b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml @@ -2,8 +2,7 @@ name: 'FBS Handler' type: module description: 'Provides integration to FBS.' package: 'OS2Forms' -core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8.8 || ^9 dependencies: - 'webform:webform' - 'advancedqueue:advancedqueue' diff --git a/modules/os2forms_fbs_handler/src/Client/FBS.php b/modules/os2forms_fbs_handler/src/Client/FBS.php index f628ee87..848ee7c8 100644 --- a/modules/os2forms_fbs_handler/src/Client/FBS.php +++ b/modules/os2forms_fbs_handler/src/Client/FBS.php @@ -4,13 +4,13 @@ use Drupal\os2forms_fbs_handler\Client\Model\Guardian; use Drupal\os2forms_fbs_handler\Client\Model\Patron; -use Fig\Http\Message\RequestMethodInterface; use GuzzleHttp\Client; +use Symfony\Component\HttpFoundation\Request; /** * Minimalistic client to create user with guardians at FBS. */ -final class FBS { +class FBS { /** * FBS session key. @@ -19,6 +19,8 @@ final class FBS { */ private string $sessionKey; + private const AUTHENTICATE_STATUS_VALID = 'VALID'; + /** * Default constructor. */ @@ -32,7 +34,7 @@ public function __construct( } /** - * Login to FBS and obtain session key. + * Login to FBS and obtain a session key. * * @return bool * TRUE on success else FALSE. @@ -80,14 +82,14 @@ public function isLoggedIn(): bool { * @throws \JsonException */ public function doUserExists(string $cpr): ?Patron { - // Check if session have been created with FBS and if not create it. + // Check if session has been created with FBS and if not creates it. if (!$this->isLoggedIn()) { $this->login(); } // Try pre-authenticate the user/parent. $json = $this->request('/external/{agency_id}/patrons/preauthenticated/v9', $cpr); - if ($json->authenticateStatus === 'VALID') { + if ($json->authenticateStatus === $this::AUTHENTICATE_STATUS_VALID) { return new Patron( $json->patron->patronId, (bool) $json->patron->receiveSms, @@ -157,9 +159,9 @@ public function updatePatron(Patron $patron): bool { ], ]; - $json = $this->request($uri, $payload, RequestMethodInterface::METHOD_PUT); + $json = $this->request($uri, $payload, Request::METHOD_PUT); - return $json->authenticateStatus === 'VALID'; + return $json->authenticateStatus === $this::AUTHENTICATE_STATUS_VALID; } /** @@ -183,7 +185,7 @@ public function createGuardian(Patron $patron, Guardian $guardian): int { 'guardian' => $guardian->toArray(), ]; - return $this->request($uri, $payload, RequestMethodInterface::METHOD_PUT); + return $this->request($uri, $payload, Request::METHOD_PUT); } /** @@ -202,7 +204,7 @@ public function createGuardian(Patron $patron, Guardian $guardian): int { * @throws \GuzzleHttp\Exception\GuzzleException * @throws \JsonException */ - private function request(string $uri, array|string $data, string $method = RequestMethodInterface::METHOD_POST): mixed { + private function request(string $uri, array|string $data, string $method = Request::METHOD_POST): mixed { $url = rtrim($this->endpoint, '/\\'); $url = $url . str_replace('{agency_id}', $this->agencyId, $uri); @@ -212,7 +214,7 @@ private function request(string $uri, array|string $data, string $method = Reque ], ]; - // The API designer at FBS don't always use JSON. So in some cases only a + // The API designer at FBS doesn't always use JSON. So in some cases only a // string should be sent. if (is_array($data)) { $options['json'] = $data; @@ -221,7 +223,7 @@ private function request(string $uri, array|string $data, string $method = Reque $options['body'] = $data; } - // If already logged in lets add the session key to the request headers. + // If already logged in, lets add the session key to the request headers. if ($this->isLoggedIn()) { $options['headers']['X-Session'] = $this->sessionKey; } diff --git a/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php index e201d2d0..2eaf0465 100644 --- a/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php +++ b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php @@ -40,10 +40,8 @@ final class FbsWebformHandler extends WebformHandlerBase { /** * The queue id. - * - * @var string */ - private string $queueId = 'os2forms_fbs_handler'; + private const QUEUE_ID = 'os2forms_fbs_handler'; /** * Constructs an FbsWebformHandler object. @@ -95,7 +93,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['queue_message'] = [ '#theme' => 'status_messages', '#message_list' => [ - 'warning' => [$this->t('Cannot get queue @queue_id', ['@queue_id' => $this->queueId])], + 'warning' => [$this->t('Cannot get queue @queue_id', ['@queue_id' => $this::QUEUE_ID])], ], ]; } @@ -204,7 +202,7 @@ public function postSave(WebformSubmissionInterface $webform_submission, $update private function getQueue(): ?Queue { $queueStorage = $this->entityTypeManager->getStorage('advancedqueue_queue'); /** @var ?\Drupal\advancedqueue\Entity\Queue $queue */ - $queue = $queueStorage->load($this->queueId); + $queue = $queueStorage->load($this::QUEUE_ID); return $queue; } From a6fc6de072c0e8c2c8271013d9b4f43b9fb64ee5 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 3 May 2024 13:42:23 +0200 Subject: [PATCH 3/3] Apply coding standards --- modules/os2forms_fbs_handler/src/Client/FBS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_fbs_handler/src/Client/FBS.php b/modules/os2forms_fbs_handler/src/Client/FBS.php index 848ee7c8..660a83a0 100644 --- a/modules/os2forms_fbs_handler/src/Client/FBS.php +++ b/modules/os2forms_fbs_handler/src/Client/FBS.php @@ -29,7 +29,7 @@ public function __construct( private readonly string $endpoint, private readonly string $agencyId, private readonly string $username, - private readonly string $password + private readonly string $password, ) { }