diff --git a/Classes/Controller/JoblistController.php b/Classes/Controller/JoblistController.php index aa77410190ecab41e0a33c47c661afdeffb035cf..390c05e32b5e332426fa18fccd459ad93bbffffd 100644 --- a/Classes/Controller/JoblistController.php +++ b/Classes/Controller/JoblistController.php @@ -28,7 +28,7 @@ namespace SGalinski\SgJobs\Controller; use SGalinski\SgJobs\Domain\Model\JobApplication; use SGalinski\SgMail\Service\MailTemplateService; -use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Log\LogLevel; use TYPO3\CMS\Core\Resource\DuplicationBehavior; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility; @@ -92,13 +92,20 @@ class JoblistController extends ActionController { * Renders the application form with an optional job * * @param JobApplication $applyData + * @param string $error */ - public function applyFormAction(JobApplication $applyData = NULL) { + public function applyFormAction(JobApplication $applyData = NULL, $error = NULL) { if ($this->request->getOriginalRequest()) { $uploadedFiles = $this->request->getOriginalRequest()->getArguments()['uploadedFiles']; $this->view->assign('uploadedFiles', $uploadedFiles); } + if ($error !== NULL) { + $logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__); + $logger->log(LogLevel::ALERT, $error, $applyData); + $this->view->assign('error', 1); + } + $jobId = $this->request->getArguments()['jobData']['uid']; if (!empty($jobId)) { $jobData = $this->jobRepository->findByUid($jobId); @@ -146,11 +153,9 @@ class JoblistController extends ActionController { ->setTargetPageUid($redirectPageId) ->build(); $this->redirectToUri($uri); - } catch (\Exception $exception) { // possible errors, because of wrong mails (maybe log that somewhere? Does this makes sense?) - GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage()); - $this->redirect('applyFormAction'); + $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]); } } @@ -178,8 +183,7 @@ class JoblistController extends ActionController { $this->handleFileUpload('certificates', $uniqueFolderName); } catch (\Exception $exception) { // possible errors, because of wrong mails - GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage()); - $this->redirect('applyFormAction'); + $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]); } $propertyMappingConfiguration = $this->arguments->getArgument('applyData')->getPropertyMappingConfiguration(); $propertyMappingConfiguration->forProperty('coverLetter')->allowAllProperties(); @@ -363,8 +367,7 @@ class JoblistController extends ActionController { fputcsv($file, $dataToInsertArr); fclose($file); } catch (\RuntimeException $exception) { - GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage()); - $this->redirect('applyFormAction'); + $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]); } } diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 79f2e5e4b63935626710ff7f9424ff17cb205f77..2ab24b4c96f56c429c017ef80ec69dd08ba3d1fb 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -210,6 +210,10 @@ <source>Female</source> <target>Weiblich</target> </trans-unit> + <trans-unit id="frontend.apply.error.general" approved="yes"> + <source>An error has occured</source> + <target>Ein Fehler ist aufgetreten</target> + </trans-unit> <trans-unit id="frontend.applyNow" approved="yes"> <source>Apply online now</source> <target>Jetzt online bewerben</target> diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 126f2fb8951ad5008e8f048a460f32dfa3d1ddf9..1b95de313fe465fdc7170496dbee3c963a0ef9f0 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -159,6 +159,9 @@ <trans-unit id="frontend.apply.gender.female"> <source>Female</source> </trans-unit> + <trans-unit id="frontend.apply.error.general"> + <source>An error has occured</source> + </trans-unit> <trans-unit id="frontend.applyNow"> <source>Apply online now</source> </trans-unit> diff --git a/Resources/Private/Templates/Joblist/ApplyForm.html b/Resources/Private/Templates/Joblist/ApplyForm.html index 0d3eca449b30ed62e4ab98bb6f19b6eb9708c805..2fabe81bef7adfdcc7aa0cba6012fd57e82aa56b 100644 --- a/Resources/Private/Templates/Joblist/ApplyForm.html +++ b/Resources/Private/Templates/Joblist/ApplyForm.html @@ -1,8 +1,12 @@ <f:layout name="Default" /> <f:section name="main"> - <f:flashMessages /> <f:form action="apply" controller="Joblist" method="post" objectName="applyData" object="{applyData}" enctype="multipart/form-data"> + <f:if condition="{error}"> + <div class="errormessage"> + <f:translate key="frontend.apply.error.general" /> + </div> + </f:if> <f:if condition="{job}"> <f:form.hidden value="{job.jobId}" property="jobId" /> <label for="apply-title"><f:translate key="frontend.apply.title" /></label>