-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from 80Quattro/powermail_11_support
Powermail 11 support
- Loading branch information
Showing
7 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StudioMitte\FriendlyCaptcha\FieldValidator; | ||
|
||
use In2code\Powermail\Domain\Validator\AbstractValidator; | ||
use StudioMitte\FriendlyCaptcha\Service\Api; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class PowermailV11Validator extends AbstractValidator | ||
{ | ||
/** | ||
* @param Mail $mail | ||
*/ | ||
public function isValid($mail): void | ||
{ | ||
if (!$this->isFormWithCaptchaField($mail) || $this->isCaptchaCheckToSkip()) { | ||
return; | ||
} | ||
|
||
$friendlyCaptchaService = GeneralUtility::makeInstance(Api::class); | ||
if (!$friendlyCaptchaService->verify()) { | ||
$this->addError( | ||
$this->translateErrorMessage('message.invalid', 'friendlycaptcha_official'), | ||
1689157219, | ||
); | ||
} | ||
} | ||
|
||
protected function isFormWithCaptchaField($mail): bool | ||
{ | ||
foreach ($mail->getForm()->getPages() as $page) { | ||
foreach ($page->getFields() as $field) { | ||
if ($field->getType() === 'friendlycaptcha') { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Captcha check should be skipped on createAction if there was a confirmationAction where the captcha was | ||
* already checked before | ||
* Note: $this->flexForm is only available in powermail 3.9 or newer | ||
*/ | ||
protected function isCaptchaCheckToSkip(): bool | ||
{ | ||
if (property_exists($this, 'flexForm')) { | ||
$confirmationActive = $this->flexForm['settings']['flexform']['main']['confirmation'] === '1'; | ||
return $this->getActionName() === 'create' && $confirmationActive; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return string "confirmation" or "create" | ||
*/ | ||
protected function getActionName(): string | ||
{ | ||
$pluginVariables = GeneralUtility::_GPmerged('tx_powermail_pi1'); | ||
return $pluginVariables['action']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
], | ||
], | ||
'state' => 'beta', | ||
'version' => '0.0.1', | ||
'version' => '0.1.0', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters