Skip to content

Commit

Permalink
Merge pull request #7 from OleksandrProtsiuk/v6.0.x
Browse files Browse the repository at this point in the history
Oro 6.0.x compatibility added
  • Loading branch information
AdamJHall authored Nov 3, 2024
2 parents 8430475 + bde85b2 commit 62e449d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 47 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ This bundle supports the following Oro Platform versions:
* Oro Platform v5.x
- Support for this version is on the "v5.x" branch

* Oro Platform v6.0.x
- Support for this version is on the "v6.0.x" branch

The Master branch will always track support for the latest released Oro Platform version.

Installation and Usage
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Oro Bundle to inject ReCAPTCHA into public forms",
"type": "project",
"require": {
"oro/platform": "5.1.*",
"oro/platform": "6.0.*",
"excelwebzone/recaptcha-bundle": "^1.5"
},
"autoload": {
Expand Down
21 changes: 9 additions & 12 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ class Configuration implements ConfigurationInterface

/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(HackOroRecaptchaExtension::ALIAS);
$rootNode = $treeBuilder->getRootNode();
Expand All @@ -41,20 +39,19 @@ public function getConfigTreeBuilder()
self::THEME => ['type' => 'scalar', 'value' => 'light'], // light/dark (default light)
self::SIZE => ['type' => 'scalar', 'value' => 'normal'], // normal/compact (default normal)
self::PROTECT_REGISTRATION => ['type' => 'boolean', 'value' => true],
self::PROTECT_CONTACT_FORM=> ['type' => 'boolean', 'value' => true],
self::PROTECT_CONTACT_FORM => ['type' => 'boolean', 'value' => true],
]
);
return $treeBuilder;
}


/**
* Returns full key name by it's last part
*
* @param $name string last part of the key name (one of the class cons can be used)
* @return string full config path key
*/
public static function getConfigKeyByName($name)
/**
* Returns full key name by it's last part
*
* @param $name string last part of the key name (one of the class cons can be used)
* @return string full config path key
*/
public static function getConfigKeyByName(string $name): string
{
return HackOroRecaptchaExtension::ALIAS . ConfigManager::SECTION_MODEL_SEPARATOR . $name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/HackOroRecaptchaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HackOroRecaptchaExtension extends Extension
/**
* @inheritdoc
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand Down
34 changes: 8 additions & 26 deletions src/Form/Extension/AbstractRecaptchaTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ abstract class AbstractRecaptchaTypeExtension extends AbstractTypeExtension
const DEFAULT_THEME = 'light';
const DEFAULT_SIZE = 'normal';

/** @var ConfigManager */
protected $configManager;
protected ConfigManager $configManager;

public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if ($this->isProtected()) {

$builder->add('recaptcha', EWZRecaptchaType::class, [
'attr' => [
'options' => [
Expand All @@ -44,44 +42,28 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
}

/**
* @param ConfigManager $configManager
*/
public function setConfigManager(ConfigManager $configManager)
public function setConfigManager(ConfigManager $configManager): void
{
$this->configManager = $configManager;
}

/**
* @return mixed
*/
protected function getTheme()
protected function getTheme(): mixed
{
return $this->getConfiguration(Configuration::THEME, self::DEFAULT_THEME);
}

/**
* @return mixed
*/
protected function getSize()
protected function getSize(): mixed
{
return $this->getConfiguration(Configuration::SIZE, self::DEFAULT_SIZE);
}

/**
* Get configuration option
* @param string $key
* @param $default
* @return mixed
*/
protected function getConfiguration(string $key, $default = null)
protected function getConfiguration(string $key, mixed $default = null): mixed
{
return $this->configManager->get(Configuration::getConfigKeyByName($key)) ?? $default;
}

/**
* @return boolean
*/
abstract public function isProtected();

}
abstract public function isProtected(): bool;
}
5 changes: 2 additions & 3 deletions src/Form/Extension/ContactUsTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@

class ContactUsTypeExtension extends AbstractRecaptchaTypeExtension
{
public function getExtendedType()
public function getExtendedType(): string
{
return ContactRequestType::class;
}

/**
* Protect the Contact Us Form?
* @return boolean
*/
public function isProtected()
public function isProtected(): bool
{
return $this->getConfiguration(Configuration::PROTECT_CONTACT_FORM, false);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Form/Extension/RegistrationTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@

class RegistrationTypeExtension extends AbstractRecaptchaTypeExtension
{
public function getExtendedType()
public function getExtendedType(): string
{
return FrontendCustomerUserRegistrationType::class;
}

/**
* Protect the Registration Form?
* @return boolean
*/
public function isProtected()
public function isProtected(): bool
{
return $this->getConfiguration(Configuration::PROTECT_REGISTRATION, false);
}
Expand All @@ -35,5 +34,4 @@ public static function getExtendedTypes(): iterable
{
return [FrontendCustomerUserRegistrationType::class];
}

}

0 comments on commit 62e449d

Please sign in to comment.