From b67ae34a26797dfd47ef18f3bb2fd88e92d82fc3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste GOMOND Date: Sat, 19 Dec 2015 14:27:50 +0100 Subject: [PATCH 1/6] Update composer.json for Symfony 3.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dc14301..4c29b00 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,10 @@ } ], "require": { - "symfony/framework-bundle": "~2.7" + "symfony/framework-bundle": "~3.0" }, "autoload": { - "psr-0": { "EWZ\\Bundle\\RecaptchaBundle\\": "" } + "psr-4": { "EWZ\\Bundle\\RecaptchaBundle\\": "" } }, "target-dir": "EWZ/Bundle/RecaptchaBundle" } From af12f1bdceb8fb4714f34d76161202fc8e5fefc8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste GOMOND Date: Sat, 19 Dec 2015 14:34:15 +0100 Subject: [PATCH 2/6] Removed target-dir from composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4c29b00..ce6c4e2 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,5 @@ }, "autoload": { "psr-4": { "EWZ\\Bundle\\RecaptchaBundle\\": "" } - }, - "target-dir": "EWZ/Bundle/RecaptchaBundle" + } } From 61ba5da2696580690a9adf70df2158e49092db9f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste GOMOND Date: Sat, 19 Dec 2015 18:58:29 +0100 Subject: [PATCH 3/6] Changement services file format and renamed certain functions --- DependencyInjection/EWZRecaptchaExtension.php | 4 +-- Form/Type/RecaptchaType.php | 2 +- Resources/config/services.xml | 29 ------------------- Resources/config/services.yml | 20 +++++++++++++ 4 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 Resources/config/services.xml create mode 100644 Resources/config/services.yml diff --git a/DependencyInjection/EWZRecaptchaExtension.php b/DependencyInjection/EWZRecaptchaExtension.php index 66cf164..db9e979 100644 --- a/DependencyInjection/EWZRecaptchaExtension.php +++ b/DependencyInjection/EWZRecaptchaExtension.php @@ -22,8 +22,8 @@ public function load(array $configs, ContainerBuilder $container) $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.xml'); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); foreach ($config as $key => $value) { $container->setParameter('ewz_recaptcha.'.$key, $value); diff --git a/Form/Type/RecaptchaType.php b/Form/Type/RecaptchaType.php index df2d7ee..b968af1 100644 --- a/Form/Type/RecaptchaType.php +++ b/Form/Type/RecaptchaType.php @@ -124,7 +124,7 @@ public function getParent() /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'ewz_recaptcha'; } diff --git a/Resources/config/services.xml b/Resources/config/services.xml deleted file mode 100644 index 5d0e018..0000000 --- a/Resources/config/services.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - EWZ\Bundle\RecaptchaBundle\Form\Type\RecaptchaType - EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueValidator - - - - - - %ewz_recaptcha.public_key% - %ewz_recaptcha.enabled% - %ewz_recaptcha.ajax% - %ewz_recaptcha.locale_key% - - - - - %ewz_recaptcha.enabled% - %ewz_recaptcha.private_key% - - %ewz_recaptcha.http_proxy% - - - diff --git a/Resources/config/services.yml b/Resources/config/services.yml new file mode 100644 index 0000000..5b04907 --- /dev/null +++ b/Resources/config/services.yml @@ -0,0 +1,20 @@ +services: + ewz_recaptcha.form.type: + class: EWZ\Bundle\RecaptchaBundle\Form\Type\RecaptchaType + arguments: + - '%ewz_recaptcha.public_key%' + - '%ewz_recaptcha.enabled%' + - '%ewz_recaptcha.ajax%' + - '%ewz_recaptcha.locale_key%' + tags: + - { name: form.type, alias: ewz_recaptcha } + + ewz_recaptcha.validator.true: + class: EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueValidator + arguments: + - '%ewz_recaptcha.enabled%' + - '%ewz_recaptcha.private_key%' + - '%ewz_recaptcha.http_proxy%' + - '@request_stack' + tags: + - { name: validator.constraint_validator } \ No newline at end of file From 7a02b548912442fdc81d80c82e9a10ae91fb907c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste GOMOND Date: Sat, 19 Dec 2015 19:36:41 +0100 Subject: [PATCH 4/6] Updated RecaptchaType --- Bridge/Form/Extension/RecaptchaExtension.php | 4 ++-- Form/Type/{RecaptchaType.php => EWZRecaptchaType.php} | 6 +++--- README.md | 10 +++++----- Resources/config/services.yml | 4 ++-- composer.json | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) rename Form/Type/{RecaptchaType.php => EWZRecaptchaType.php} (96%) diff --git a/Bridge/Form/Extension/RecaptchaExtension.php b/Bridge/Form/Extension/RecaptchaExtension.php index 38ed54a..192a221 100644 --- a/Bridge/Form/Extension/RecaptchaExtension.php +++ b/Bridge/Form/Extension/RecaptchaExtension.php @@ -4,7 +4,7 @@ use Silex\Application; use Symfony\Component\Form\AbstractExtension; -use EWZ\Bundle\RecaptchaBundle\Form\Type\RecaptchaType; +use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType; /** * Extends form to register captcha type @@ -36,7 +36,7 @@ public function __construct(Application $app) protected function loadTypes() { return array( - new RecaptchaType( + new EWZRecaptchaType( $this->app['ewz_recaptcha.public_key'], $this->app['ewz_recaptcha.enabled'], $this->app['ewz_recaptcha.ajax'], diff --git a/Form/Type/RecaptchaType.php b/Form/Type/EWZRecaptchaType.php similarity index 96% rename from Form/Type/RecaptchaType.php rename to Form/Type/EWZRecaptchaType.php index b968af1..781f093 100644 --- a/Form/Type/RecaptchaType.php +++ b/Form/Type/EWZRecaptchaType.php @@ -1,7 +1,7 @@ add('recaptcha', 'ewz_recaptcha'); + $builder->add('recaptcha', EWZRecaptchaType::class); // ... } ``` @@ -120,7 +120,7 @@ You can pass extra options to reCAPTCHA with the "attr > options" option: public function buildForm(FormBuilder $builder, array $options) { // ... - $builder->add('recaptcha', 'ewz_recaptcha', array( + $builder->add('recaptcha', EWZRecaptchaType::class, array( 'attr' => array( 'options' => array( 'theme' => 'light', @@ -157,7 +157,7 @@ use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrue as RecaptchaTrue; public function buildForm(FormBuilder $builder, array $options) { // ... - $builder->add('recaptcha', 'ewz_recaptcha', array( + $builder->add('recaptcha', EWZRecaptchaType::class, array( 'attr' => array( 'options' => array( 'theme' => 'light', @@ -213,7 +213,7 @@ using JavaScript:
diff --git a/Resources/views/Form/ewz_recaptcha_widget.html.twig b/Resources/views/Form/ewz_recaptcha_widget.html.twig index bed09d9..acf9fe8 100644 --- a/Resources/views/Form/ewz_recaptcha_widget.html.twig +++ b/Resources/views/Form/ewz_recaptcha_widget.html.twig @@ -14,10 +14,10 @@ > -
+
@@ -32,7 +32,7 @@ script.type = 'text/javascript'; script.onload = function() { Recaptcha.create('{{ form.vars.public_key }}', 'ewz_recaptcha_div', {{ attr.options|default({})|json_encode|raw }}); - } + }; script.src = '{{ form.vars.url_api }}'; document.getElementsByTagName('head')[0].appendChild(script); diff --git a/Validator/Constraints/IsTrueValidator.php b/Validator/Constraints/IsTrueValidator.php index 3e55d24..3c06ac1 100755 --- a/Validator/Constraints/IsTrueValidator.php +++ b/Validator/Constraints/IsTrueValidator.php @@ -64,7 +64,7 @@ public function validate($value, Constraint $constraint) { // if recaptcha is disabled, always valid if (!$this->enabled) { - return true; + return; } // define variable for recaptcha check answer From 5f0b0e9da7ccdb5d2c38b52cc9d727980f32d778 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste GOMOND Date: Sat, 19 Dec 2015 20:15:48 +0100 Subject: [PATCH 6/6] Fixed validator --- Resources/config/services.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 2a96bb5..c17fac3 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -14,7 +14,7 @@ services: arguments: - '%ewz_recaptcha.enabled%' - '%ewz_recaptcha.private_key%' - - '%ewz_recaptcha.http_proxy%' - '@request_stack' + - '%ewz_recaptcha.http_proxy%' tags: - - { name: validator.constraint_validator } \ No newline at end of file + - { name: validator.constraint_validator, alias: 'ewz_recaptcha.true' } \ No newline at end of file