Skip to content

Commit

Permalink
Merge branch 'feature-friendly-captcha-v2' of github.com:80Quattro/fr…
Browse files Browse the repository at this point in the history
…iendlycaptcha-typo3 into feature-friendly-captcha-v2
  • Loading branch information
80Quattro committed Oct 31, 2024
2 parents c1c1448 + de159b0 commit 33876c4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
16 changes: 1 addition & 15 deletions Classes/ViewHelpers/ConfigurationViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
namespace StudioMitte\FriendlyCaptcha\ViewHelpers;

use StudioMitte\FriendlyCaptcha\Configuration;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

class ConfigurationViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
public static function render()
{
$configuration = new Configuration();
return [
Expand All @@ -25,16 +23,4 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
'enabled' => $configuration->isEnabled(),
];
}

protected static function getLanguageIsoCode(): string
{
$language = $GLOBALS['TYPO3_REQUEST']->getAttribute('language');
if (!$language) {
return '';
}
if ((new Typo3Version())->getMajorVersion() >= 12) {
return $language->getLocale()->getLanguageCode();
}
return $language->getTwoLetterIsoCode();
}
}
2 changes: 1 addition & 1 deletion Configuration/PageTsConfig/powermail.typoscript
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add FriendlyCaptcha field to Powermail
tx_powermail.flexForm.type.addFieldOptions {
friendlycaptcha = FriendlyCaptcha
friendlycaptcha = FriendlyCaptcha V2
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<f:if condition="{captchaConfiguration.enabled}">
<f:then>
<f:asset.script defer="1" async="1" identifier="friendlycaptcha" src="{captchaConfiguration.jsPath}" />
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" data-lang="{captchaConfiguration.languageIsoCode}" data-puzzle-endpoint="{captchaConfiguration.puzzleUrl}"></div>
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" {f:if(condition: '{captchaConfiguration.puzzleEndpoint}', then: 'data-api-endpoint="{captchaConfiguration.puzzleEndpoint}"')}></div>
</f:then>
<f:else>
<p>{f:translate(key:'LLL:EXT:friendlycaptcha_official/Resources/Private/Language/locallang.xlf:configuration_missing')}</p>
Expand Down
9 changes: 3 additions & 6 deletions Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use StudioMitte\FriendlyCaptcha\Tests\RequestTrait;
use StudioMitte\FriendlyCaptcha\ViewHelpers\ConfigurationViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3\TestingFramework\Core\BaseTestCase;

class ConfigurationViewHelperTest extends BaseTestCase
Expand All @@ -19,16 +18,14 @@ class ConfigurationViewHelperTest extends BaseTestCase
public function viewHelperReturnsProperConfiguration()
{
self::setupRequest();

$renderingContext = new class () extends RenderingContext {
public function __construct() {}
};
$configurationViewHelper = new ConfigurationViewHelper();

self::assertSame([
'siteKey' => '1234',
'verifyUrl' => 'https://verify,https://verify2',
'puzzleEndpoint' => '',
'jsPath' => 'EXT:friendlycaptcha_official/Resources/Public/JavaScript/lib/[email protected]',
'enabled' => true,
], ConfigurationViewHelper::renderStatic([], static fn() => '', $renderingContext));
], $configurationViewHelper->render());
}
}

0 comments on commit 33876c4

Please sign in to comment.