22
33namespace Drupal \os2forms_digital_post \Helper ;
44
5+ use Drupal \Core \Logger \LoggerChannelFactoryInterface ;
56use Drupal \os2forms_cpr_lookup \CPR \CprServiceResult ;
67use Drupal \os2forms_digital_post \Exception \CprElementNotFoundInSubmissionException ;
8+ use Drupal \os2forms_digital_post \Exception \SubmissionNotFoundException ;
79use Drupal \webform \WebformSubmissionInterface ;
810use Drupal \Core \Entity \EntityTypeManagerInterface ;
911use Drupal \Core \Render \Renderer ;
@@ -51,15 +53,23 @@ final class WebformHelper {
5153 */
5254 protected $ templateManager ;
5355
56+ /**
57+ * The logger.
58+ *
59+ * @var \Drupal\Core\Logger\LoggerChannelInterface
60+ */
61+ protected $ logger ;
62+
5463 /**
5564 * Constructor.
5665 */
57- public function __construct (EntityTypeManagerInterface $ entity_type_manager , Renderer $ renderer , CprServiceInterface $ cprService , PrintServiceConsumer $ printServiceConsumer , TemplateManager $ templateManager ) {
66+ public function __construct (EntityTypeManagerInterface $ entity_type_manager , Renderer $ renderer , CprServiceInterface $ cprService , PrintServiceConsumer $ printServiceConsumer , TemplateManager $ templateManager, LoggerChannelFactoryInterface $ loggerChannelFactory ) {
5867 $ this ->entityTypeManager = $ entity_type_manager ;
5968 $ this ->renderer = $ renderer ;
6069 $ this ->cprService = $ cprService ;
6170 $ this ->printServiceConsumer = $ printServiceConsumer ;
6271 $ this ->templateManager = $ templateManager ;
72+ $ this ->logger = $ loggerChannelFactory ->get ('os2forms_digital_post ' );
6373 }
6474
6575 /**
@@ -92,7 +102,7 @@ public function getTemplateContext(WebformSubmissionInterface $webformSubmission
92102 return [
93103 'label ' => $ webform ->label (),
94104 'recipient ' => $ recipient ,
95- 'submission ' => $ webformSubmissionRendered
105+ 'submission ' => $ webformSubmissionRendered,
96106 ];
97107 }
98108
@@ -104,19 +114,28 @@ public function getTemplateContext(WebformSubmissionInterface $webformSubmission
104114 * @param array $handlerConfiguration
105115 * Handler config.
106116 *
107- * @throws CprElementNotFoundInSubmissionException
117+ * @throws \Drupal\os2forms_digital_post\Exception\CprElementNotFoundInSubmissionException
118+ * @throws \Drupal\os2forms_digital_post\Exception\SubmissionNotFoundException
108119 * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
109120 * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
110121 * @throws \ItkDev\Serviceplatformen\Service\Exception\ServiceException
111122 */
112123 public function sendDigitalPost (string $ submissionId , array $ handlerConfiguration ) {
113124 /** @var \Drupal\webform\Entity\WebformSubmission $submission */
114125 $ webform_submission = $ this ->getSubmission ($ submissionId );
126+ if (empty ($ webform_submission )) {
127+ $ this ->logger ->error (
128+ 'Cannot load submission @submissionId ' ,
129+ ['@submissionId ' => $ submissionId ]
130+ );
131+
132+ throw new SubmissionNotFoundException (sprintf ('Submission %s not found ' , $ submissionId ));
133+ }
115134
116135 $ submissionData = $ webform_submission ->getData ();
117136
118137 if (!array_key_exists ($ handlerConfiguration ['cpr_element ' ], $ submissionData )) {
119- $ this ->getLogger () ->error (
138+ $ this ->logger ->error (
120139 'The chosen CPR element not found in submission! '
121140 );
122141
@@ -178,4 +197,5 @@ private function getSubmission(string $submissionId) {
178197 $ storage = $ this ->entityTypeManager ->getStorage ('webform_submission ' );
179198 return $ storage ->load ($ submissionId );
180199 }
200+
181201}
0 commit comments