Skip to content

Commit

Permalink
Merge pull request #5 from 80Quattro/powermail_11_support
Browse files Browse the repository at this point in the history
Powermail 11 support
  • Loading branch information
80Quattro authored Oct 19, 2023
2 parents e5a44b3 + 328491f commit cb6b1c6
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
12 changes: 8 additions & 4 deletions Build/php-cs-fixer/php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@
'@PER' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'braces' => ['allow_single_line_closure' => true],
'control_structure_braces' => true,
'control_structure_continuation_position' => true,
'declare_parentheses' => true,
'no_multiple_statements_per_line' => true,
'braces_position' => true,
'statement_indentation' => true,
'no_extra_blank_lines' => true,
'cast_spaces' => ['space' => 'none'],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'dir_constant' => true,
'function_typehint_space' => true,
'new_with_parentheses' => true,
'lowercase_cast' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
Expand Down
65 changes: 65 additions & 0 deletions Classes/FieldValidator/PowermailV11Validator.php
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'];
}
}
5 changes: 5 additions & 0 deletions Classes/FieldValidator/PowermailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function validate($mail): Result
return $result;
}

public function isValid(mixed $mail): void
{
return;
}

protected function isFormWithCaptchaField($mail): bool
{
foreach ($mail->getForm()->getPages() as $page) {
Expand Down
9 changes: 8 additions & 1 deletion Configuration/TypoScript/Powermail/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugin.tx_powermail {
981818 = EXT:friendlycaptcha_official/Resources/Private/Powermail/Partials
}
}

settings.setup.validators {
981818 {
class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailValidator
Expand All @@ -14,3 +13,11 @@ plugin.tx_powermail {
}
}
}

[compatVersion("12.4")]
plugin.tx_powermail.settings.setup.validators {
981818 {
class = StudioMitte\FriendlyCaptcha\FieldValidator\PowermailV11Validator
}
}
[global]
4 changes: 1 addition & 3 deletions Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public function viewHelperReturnsProperConfiguration()
self::setupRequest();

$renderingContext = new class () extends RenderingContext {
public function __construct()
{
}
public function __construct() {}
};
self::assertSame([
'languageIsoCode' => 'en',
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
],
],
'state' => 'beta',
'version' => '0.0.1',
'version' => '0.1.0',
];
5 changes: 5 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
');
}

if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('powermail')) {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup('@import "EXT:friendlycaptcha_official/Configuration/TypoScript/Powermail/setup.typoscript');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('@import "EXT:friendlycaptcha_official/Configuration/PageTsConfig/powermail.typoscript"');
}

if (!isset($GLOBALS['TYPO3_CONF_VARS']['LOG']['StudioMitte']['FriendlyCaptcha']['writerConfiguration'])) {
$GLOBALS['TYPO3_CONF_VARS']['LOG']['StudioMitte']['FriendlyCaptcha']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::WARNING => [
Expand Down

0 comments on commit cb6b1c6

Please sign in to comment.