Skip to content

Commit

Permalink
Merge pull request #77 from MJBGO/3.0-update
Browse files Browse the repository at this point in the history
Symfony 3.0 support
  • Loading branch information
excelwebzone committed Dec 19, 2015
2 parents 024f8ad + 5f0b0e9 commit 9ef5b5a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Bridge/Form/Extension/RecaptchaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/EWZRecaptchaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace EWZ\Bundle\RecaptchaBundle\Form\Type;

use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\AbstractType;
Expand All @@ -10,7 +10,7 @@
/**
* A field for entering a recaptcha text.
*/
class RecaptchaType extends AbstractType
class EWZRecaptchaType extends AbstractType
{
/**
* The reCAPTCHA server URL's
Expand Down Expand Up @@ -51,6 +51,7 @@ class RecaptchaType extends AbstractType
*
* @param string $publicKey Recaptcha public key
* @param Boolean $enabled Recaptache status
* @param Boolean $ajax Ajax status
* @param string $language Language or locale code
*/
public function __construct($publicKey, $enabled, $ajax, $language)
Expand Down Expand Up @@ -118,13 +119,13 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getParent()
{
return 'form';
return TextType::class;
}

/**
* {@inheritdoc}
*/
public function getName()
public function getBlockPrefix()
{
return 'ewz_recaptcha';
}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ When creating a new form class add the following line to create the field:
public function buildForm(FormBuilder $builder, array $options)
{
// ...
$builder->add('recaptcha', 'ewz_recaptcha');
$builder->add('recaptcha', EWZRecaptchaType::class);
// ...
}
```
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -213,7 +213,7 @@ using JavaScript:
<div id="recaptcha-container"></div>
<script type="text/javascript">
$(document).ready(function() {
$.getScript("<?php echo \EWZ\Bundle\RecaptchaBundle\Form\Type\RecaptchaType::RECAPTCHA_API_JS_SERVER ?>", function() {
$.getScript("<?php echo \EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType::RECAPTCHA_API_JS_SERVER ?>", function() {
Recaptcha.create("<?php echo $form['recaptcha']->get('public_key') ?>", "recaptcha-container", {
theme: "clean",
});
Expand All @@ -228,7 +228,7 @@ using JavaScript:
<div id="recaptcha-container"></div>
<script type="text/javascript">
$(document).ready(function() {
$.getScript("{{ constant('\\EWZ\\Bundle\\RecaptchaBundle\\Form\\Type\\RecaptchaType::RECAPTCHA_API_JS_SERVER') }}", function() {
$.getScript("{{ constant('\\EWZ\\Bundle\\RecaptchaBundle\\Form\\Type\\EWZRecaptchaType::RECAPTCHA_API_JS_SERVER') }}", function() {
Recaptcha.create("{{ form.recaptcha.get('public_key') }}", "recaptcha-container", {
theme: "clean"
});
Expand Down
29 changes: 0 additions & 29 deletions Resources/config/services.xml

This file was deleted.

20 changes: 20 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
ewz_recaptcha.form.type:
class: EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType
arguments:
- '%ewz_recaptcha.public_key%'
- '%ewz_recaptcha.enabled%'
- '%ewz_recaptcha.ajax%'
- '%ewz_recaptcha.locale_key%'
tags:
- { name: form.type }

ewz_recaptcha.validator.true:
class: EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueValidator
arguments:
- '%ewz_recaptcha.enabled%'
- '%ewz_recaptcha.private_key%'
- '@request_stack'
- '%ewz_recaptcha.http_proxy%'
tags:
- { name: validator.constraint_validator, alias: 'ewz_recaptcha.true' }
6 changes: 3 additions & 3 deletions Resources/views/Form/ewz_recaptcha_widget.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
>
</iframe>
</div>
<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;">
<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0; padding: 0; right: 25px;">
<textarea id="g-recaptcha-response" name="g-recaptcha-response"
class="g-recaptcha-response"
style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0px; padding: 0px; resize: none;"
style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0; padding: 0; resize: none;"
>
</textarea>
</div>
Expand All @@ -30,7 +30,7 @@ class="g-recaptcha-response"
script.type = 'text/javascript';
script.onload = function() {
Recaptcha.create('<?php echo $public_key ?>', 'ewz_recaptcha_div', <?php echo json_encode($attr['options']) ?>);
}
};
script.src = '<?php echo $url_api ?>';
document.getElementsByTagName('head')[0].appendChild(script);
</script>
Expand Down
6 changes: 3 additions & 3 deletions Resources/views/Form/ewz_recaptcha_widget.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
>
</iframe>
</div>
<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;">
<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0; padding: 0; right: 25px;">
<textarea id="g-recaptcha-response" name="g-recaptcha-response"
class="g-recaptcha-response"
style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0px; padding: 0px; resize: none;"
style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0; padding: 0; resize: none;"
>
</textarea>
</div>
Expand All @@ -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);
</script>
Expand Down
2 changes: 1 addition & 1 deletion Validator/Constraints/IsTrueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
}
],
"require": {
"symfony/framework-bundle": "~2.7"
"symfony/framework-bundle": "~3.0"
},
"autoload": {
"psr-0": { "EWZ\\Bundle\\RecaptchaBundle\\": "" }
},
"target-dir": "EWZ/Bundle/RecaptchaBundle"
}
"psr-4": { "EWZ\\Bundle\\RecaptchaBundle\\": "" }
}
}

0 comments on commit 9ef5b5a

Please sign in to comment.