Skip to content

Commit

Permalink
Merge pull request #4 from Pixel-Open/release/100.2.0
Browse files Browse the repository at this point in the history
Release/100.2.0
  • Loading branch information
magentix authored Dec 12, 2023
2 parents f789ca4 + 74891f2 commit 4d019e1
Show file tree
Hide file tree
Showing 44 changed files with 1,130 additions and 243 deletions.
20 changes: 20 additions & 0 deletions Block/Turnstile.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public function getAction(): string
return $this->getData('action') ?: $this->config->getAction();
}

/**
* Retrieve size, will override the config if set for block in layout
*
* @return string|null
*/
public function getSize(): ?string
{
return $this->getData('size');
}

/**
* Retrieve theme, will override the config if set for block in layout
*
* @return string|null
*/
public function getTheme(): ?string
{
return $this->getData('theme');
}

/**
* Retrieve id
*
Expand Down
8 changes: 4 additions & 4 deletions Block/Turnstile/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace PixelOpen\CloudflareTurnstile\Block\Turnstile;

use PixelOpen\CloudflareTurnstile\Model\Turnstile\ConfigProvider;
use PixelOpen\CloudflareTurnstile\Model\Turnstile\ConfigProviderInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
Expand All @@ -19,18 +19,18 @@ class Config extends Template
{
protected SerializerInterface $serializer;

protected ConfigProvider $configProvider;
protected ConfigProviderInterface $configProvider;

/**
* @param Context $context
* @param SerializerInterface $serializer
* @param ConfigProvider $configProvider
* @param ConfigProviderInterface $configProvider
* @param mixed[] $data
*/
public function __construct(
Context $context,
SerializerInterface $serializer,
ConfigProvider $configProvider,
ConfigProviderInterface $configProvider,
array $data = []
) {
$this->serializer = $serializer;
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 100.2.0

- Admin "login" and "reset password" forms validation
- Validation added on guest checkout login form
- Widget size configuration
- French translation
- Fix API request on each page with authentication popup
- Fix widget resetting on ajax call

## 100.1.2

- Config path updated
Expand Down
85 changes: 72 additions & 13 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,37 @@

class Config extends AbstractHelper
{
public const TURNSTILE_CONFIG_PATH_ENABLED = 'pixel_open_cloudflare_turnstile/settings/enabled';
public const TURNSTILE_CONFIG_PATH_SECRET_KEY = 'pixel_open_cloudflare_turnstile/settings/secret_key';
public const TURNSTILE_CONFIG_PATH_SITEKEY = 'pixel_open_cloudflare_turnstile/settings/sitekey';
public const TURNSTILE_CONFIG_PATH_THEME = 'pixel_open_cloudflare_turnstile/settings/theme';
public const TURNSTILE_CONFIG_PATH_FORMS = 'pixel_open_cloudflare_turnstile/settings/forms';

public const TURNSTILE_CONFIG_PATH_FRONTEND_ENABLED = 'pixel_open_cloudflare_turnstile/frontend/enabled';
public const TURNSTILE_CONFIG_PATH_FRONTEND_THEME = 'pixel_open_cloudflare_turnstile/frontend/theme';
public const TURNSTILE_CONFIG_PATH_FRONTEND_SIZE = 'pixel_open_cloudflare_turnstile/frontend/size';
public const TURNSTILE_CONFIG_PATH_FRONTEND_FORMS = 'pixel_open_cloudflare_turnstile/frontend/forms';

public const TURNSTILE_CONFIG_PATH_ADMINHTML_ENABLED = 'pixel_open_cloudflare_turnstile/adminhtml/enabled';
public const TURNSTILE_CONFIG_PATH_ADMINHTML_THEME = 'pixel_open_cloudflare_turnstile/adminhtml/theme';
public const TURNSTILE_CONFIG_PATH_ADMINHTML_SIZE = 'pixel_open_cloudflare_turnstile/adminhtml/size';
public const TURNSTILE_CONFIG_PATH_ADMINHTML_FORMS = 'pixel_open_cloudflare_turnstile/adminhtml/forms';

/**
* Is Turnstile enabled on front
*
* @return bool
*/
public function isEnabledOnFront(): bool
{
return $this->scopeConfig->isSetFlag(self::TURNSTILE_CONFIG_PATH_FRONTEND_ENABLED);
}

/**
* Is Turnstile enabled
* Is Turnstile enabled on admin
*
* @return bool
*/
public function isEnabled(): bool
public function isEnabledOnAdmin(): bool
{
return $this->scopeConfig->isSetFlag(self::TURNSTILE_CONFIG_PATH_ENABLED);
return $this->scopeConfig->isSetFlag(self::TURNSTILE_CONFIG_PATH_ADMINHTML_ENABLED);
}

/**
Expand All @@ -45,29 +62,71 @@ public function getSecretKey(): string
*
* @return string
*/
public function getSitekey(): string
public function getSiteKey(): string
{
return (string)$this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_SITEKEY);
}

/**
* Retrieve theme
* Retrieve frontend theme
*
* @return string
*/
public function getFrontendTheme(): string
{
return (string)$this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_FRONTEND_THEME);
}

/**
* Retrieve admin theme
*
* @return string
*/
public function getTheme(): string
public function getAdminTheme(): string
{
return (string)$this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_THEME);
return (string)$this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_ADMINHTML_THEME);
}

/**
* Retrieve frontend size
*
* @return string
*/
public function getFrontendSize(): string
{
return (string)$this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_FRONTEND_SIZE);
}

/**
* Retrieve admin size
*
* @return string
*/
public function getAdminSize(): string
{
return (string)$this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_ADMINHTML_SIZE);
}

/**
* Retrieve enabled frontend forms
*
* @return string[]
*/
public function getFrontendForms(): array
{
$forms = $this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_FRONTEND_FORMS);

return $forms ? array_filter(explode(',', $forms)) : [];
}

/**
* Retrieve enabled forms
* Retrieve enabled admin forms
*
* @return string[]
*/
public function getForms(): array
public function getAdminForms(): array
{
$forms = $this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_FORMS);
$forms = $this->scopeConfig->getValue(self::TURNSTILE_CONFIG_PATH_ADMINHTML_FORMS);

return $forms ? array_filter(explode(',', $forms)) : [];
}
Expand Down
21 changes: 2 additions & 19 deletions Model/Config/Source/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@

use Magento\Framework\Data\OptionSourceInterface;

class Forms implements OptionSourceInterface
abstract class Forms implements OptionSourceInterface
{
public const FORM_CONTACT = 'contact';
public const FORM_REGISTER = 'register';
public const FORM_LOGIN = 'login';
public const FORM_LOGIN_AJAX = 'login-ajax';
public const FORM_PASSWORD = 'password';
public const FORM_REVIEW = 'review';

/**
* Get options as array
*
Expand All @@ -45,15 +38,5 @@ public function toOptionArray(): array
*
* @return string[]
*/
public function toArray(): array
{
return [
self::FORM_CONTACT,
self::FORM_REGISTER,
self::FORM_LOGIN,
self::FORM_LOGIN_AJAX,
self::FORM_PASSWORD,
self::FORM_REVIEW,
];
}
abstract public function toArray(): array;
}
27 changes: 27 additions & 0 deletions Model/Config/Source/Forms/Adminhtml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PixelOpen\CloudflareTurnstile\Model\Config\Source\Forms;

use PixelOpen\CloudflareTurnstile\Model\Config\Source\Forms;

class Adminhtml extends Forms
{
public const FORM_LOGIN = 'login';
public const FORM_PASSWORD = 'password';

public function toArray(): array
{
return [
self::FORM_LOGIN,
self::FORM_PASSWORD,
];
}
}
35 changes: 35 additions & 0 deletions Model/Config/Source/Forms/Frontend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PixelOpen\CloudflareTurnstile\Model\Config\Source\Forms;

use PixelOpen\CloudflareTurnstile\Model\Config\Source\Forms;

class Frontend extends Forms
{
public const FORM_CONTACT = 'contact';
public const FORM_REGISTER = 'register';
public const FORM_LOGIN = 'login';
public const FORM_LOGIN_AJAX = 'login-ajax';
public const FORM_PASSWORD = 'password';
public const FORM_REVIEW = 'review';

public function toArray(): array
{
return [
self::FORM_CONTACT,
self::FORM_REGISTER,
self::FORM_LOGIN,
self::FORM_LOGIN_AJAX,
self::FORM_PASSWORD,
self::FORM_REVIEW,
];
}
}
48 changes: 48 additions & 0 deletions Model/Config/Source/Size.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PixelOpen\CloudflareTurnstile\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;

class Size implements OptionSourceInterface
{
public const SIZE_NORMAL = 'normal';
public const SIZE_COMPACT = 'compact';

/**
* Get options as array
*
* @return string[][]
*/
public function toOptionArray(): array
{
$options = [];

foreach ($this->toArray() as $value) {
$options[] = [
'value' => $value,
'label' => $value,
];
}

return $options;
}

/**
* Get options as array
*
* @return string[]
*/
public function toArray(): array
{
return [self::SIZE_NORMAL, self::SIZE_COMPACT];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

declare(strict_types=1);

namespace PixelOpen\CloudflareTurnstile\Model\Turnstile;
namespace PixelOpen\CloudflareTurnstile\Model\Turnstile\Adminhtml;

use PixelOpen\CloudflareTurnstile\Helper\Config;
use Magento\Checkout\Model\ConfigProviderInterface;
use PixelOpen\CloudflareTurnstile\Model\Turnstile\ConfigProviderInterface;

class ConfigProvider implements ConfigProviderInterface
{
Expand All @@ -32,10 +32,12 @@ public function __construct(
public function getConfig(): array
{
return [
'turnstile' => [
'sitekey' => $this->config->getSitekey(),
'theme' => $this->config->getTheme(),
'forms' => $this->config->getForms(),
'config' => [
'enabled' => $this->config->isEnabledOnAdmin(),
'sitekey' => $this->config->getSiteKey(),
'theme' => $this->config->getAdminTheme(),
'size' => $this->config->getAdminSize(),
'forms' => $this->config->getAdminForms(),
]
];
}
Expand Down
21 changes: 21 additions & 0 deletions Model/Turnstile/ConfigProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PixelOpen\CloudflareTurnstile\Model\Turnstile;

interface ConfigProviderInterface
{
/**
* Retrieve assoc array of turnstile configuration
*
* @return array
*/
public function getConfig(): array;
}
Loading

0 comments on commit 4d019e1

Please sign in to comment.