summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornaveenvalecha2016-01-15 00:26:14 +0100
committerhass2016-01-15 00:26:14 +0100
commita3e1c737fc45ae8cd03eba00d6e8cfbccb318034 (patch)
treeefbe178acb561a3701bdb3ff5b1e523717badf58
parentc54b7a41d3e97ea2c29b2f62a3a91386bf7b4c9a (diff)
Replace procedural t() with OO t() and Use form api number element
-rw-r--r--src/Form/ReCaptchaAdminSettingsForm.php54
-rw-r--r--src/Tests/ReCaptchaBasicTest.php2
2 files changed, 21 insertions, 35 deletions
diff --git a/src/Form/ReCaptchaAdminSettingsForm.php b/src/Form/ReCaptchaAdminSettingsForm.php
index f7def94..7fccde5 100644
--- a/src/Form/ReCaptchaAdminSettingsForm.php
+++ b/src/Form/ReCaptchaAdminSettingsForm.php
@@ -37,75 +37,75 @@ class ReCaptchaAdminSettingsForm extends ConfigFormBase {
$form['general'] = [
'#type' => 'details',
- '#title' => t('General settings'),
+ '#title' => $this->t('General settings'),
'#open' => TRUE,
];
$form['general']['recaptcha_site_key'] = [
'#default_value' => $config->get('site_key'),
- '#description' => t('The site key given to you when you <a href=":url">register for reCAPTCHA</a>.', [':url' => 'http://www.google.com/recaptcha/admin']),
+ '#description' => $this->t('The site key given to you when you <a href=":url">register for reCAPTCHA</a>.', [':url' => 'http://www.google.com/recaptcha/admin']),
'#maxlength' => 40,
'#required' => TRUE,
- '#title' => t('Site key'),
+ '#title' => $this->t('Site key'),
'#type' => 'textfield',
];
$form['general']['recaptcha_secret_key'] = [
'#default_value' => $config->get('secret_key'),
- '#description' => t('The secret key given to you when you <a href=":url">register for reCAPTCHA</a>.', [':url' => 'http://www.google.com/recaptcha/admin']),
+ '#description' => $this->t('The secret key given to you when you <a href=":url">register for reCAPTCHA</a>.', [':url' => 'http://www.google.com/recaptcha/admin']),
'#maxlength' => 40,
'#required' => TRUE,
- '#title' => t('Secret key'),
+ '#title' => $this->t('Secret key'),
'#type' => 'textfield',
];
// Widget configurations.
$form['widget'] = [
'#type' => 'details',
- '#title' => t('Widget settings'),
+ '#title' => $this->t('Widget settings'),
'#open' => TRUE,
];
$form['widget']['recaptcha_theme'] = [
'#default_value' => $config->get('widget.theme'),
- '#description' => t('Defines which theme to use for reCAPTCHA.'),
+ '#description' => $this->t('Defines which theme to use for reCAPTCHA.'),
'#options' => [
'light' => t('Light (default)'),
'dark' => t('Dark'),
],
- '#title' => t('Theme'),
+ '#title' => $this->t('Theme'),
'#type' => 'select',
];
$form['widget']['recaptcha_type'] = [
'#default_value' => $config->get('widget.type'),
- '#description' => t('The type of CAPTCHA to serve.'),
+ '#description' => $this->t('The type of CAPTCHA to serve.'),
'#options' => [
- 'image' => t('Image (default)'),
- 'audio' => t('Audio'),
+ 'image' => $this->t('Image (default)'),
+ 'audio' => $this->t('Audio'),
],
- '#title' => t('Type'),
+ '#title' => $this->t('Type'),
'#type' => 'select',
];
$form['widget']['recaptcha_size'] = [
'#default_value' => $config->get('widget.size'),
- '#description' => t('The size of CAPTCHA to serve.'),
+ '#description' => $this->t('The size of CAPTCHA to serve.'),
'#options' => [
- '' => t('Normal (default)'),
- 'compact' => t('Compact'),
+ '' => $this->t('Normal (default)'),
+ 'compact' => $this->t('Compact'),
],
- '#title' => t('Size'),
+ '#title' => $this->t('Size'),
'#type' => 'select',
];
$form['widget']['recaptcha_tabindex'] = [
'#default_value' => $config->get('widget.tabindex'),
- '#description' => t('Set the <a href=":tabindex">tabindex</a> of the widget and challenge (Default = 0). If other elements in your page use tabindex, it should be set to make user navigation easier.', [':tabindex' => Url::fromUri('http://www.w3.org/TR/html4/interact/forms.html', ['fragment' => 'adef-tabindex'])->toString()]),
+ '#description' => $this->t('Set the <a href=":tabindex">tabindex</a> of the widget and challenge (Default = 0). If other elements in your page use tabindex, it should be set to make user navigation easier.', [':tabindex' => Url::fromUri('http://www.w3.org/TR/html4/interact/forms.html', ['fragment' => 'adef-tabindex'])->toString()]),
'#maxlength' => 4,
- '#title' => t('Tabindex'),
- '#type' => 'textfield',
+ '#title' => $this->t('Tabindex'),
+ '#type' => 'number',
];
$form['widget']['recaptcha_noscript'] = [
'#default_value' => $config->get('widget.noscript'),
- '#description' => t('If JavaScript is a requirement for your site, you should <strong>not</strong> enable this feature. With this enabled, a compatibility layer will be added to the captcha to support non-js users.'),
- '#title' => t('Enable fallback for browsers with JavaScript disabled'),
+ '#description' => $this->t('If JavaScript is a requirement for your site, you should <strong>not</strong> enable this feature. With this enabled, a compatibility layer will be added to the captcha to support non-js users.'),
+ '#title' => $this->t('Enable fallback for browsers with JavaScript disabled'),
'#type' => 'checkbox',
];
@@ -115,18 +115,6 @@ class ReCaptchaAdminSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
- public function validateForm(array &$form, FormStateInterface $form_state) {
- parent::validateForm($form, $form_state);
-
- $tabindex = $form_state->getValue('recaptcha_tabindex');
- if (!is_numeric($tabindex)) {
- $form_state->setErrorByName('recaptcha_tabindex', t('The tabindex must be an integer.'));
- }
- }
-
- /**
- * {@inheritdoc}
- */
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('recaptcha.settings');
$config
diff --git a/src/Tests/ReCaptchaBasicTest.php b/src/Tests/ReCaptchaBasicTest.php
index 1ffc133..9f36c4e 100644
--- a/src/Tests/ReCaptchaBasicTest.php
+++ b/src/Tests/ReCaptchaBasicTest.php
@@ -72,12 +72,10 @@ class ReCaptchaBasicTest extends WebTestBase {
// Check form validation.
$edit['recaptcha_site_key'] = '';
$edit['recaptcha_secret_key'] = '';
- $edit['recaptcha_tabindex'] = $this->randomMachineName(2);
$this->drupalPostForm('admin/config/people/captcha/recaptcha', $edit, t('Save configuration'));
$this->assertRaw(t('Site key field is required.'), '[testReCaptchaConfiguration]: Empty site key detected.');
$this->assertRaw(t('Secret key field is required.'), '[testReCaptchaConfiguration]: Empty secret key detected.');
- $this->assertRaw(t('The tabindex must be an integer.'), '[testReCaptchaConfiguration]: Invalid value for tab index detected.');
// Save form with valid values.
$edit['recaptcha_site_key'] = $site_key;