Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
honeypot-3461131
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
honeypot-3461131
Commits
e050fb42
Commit
e050fb42
authored
10 years ago
by
Marc Ingram
Committed by
Jeff Geerling
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2322247
by marcingy: Update honeypot module to use form state interface.
parent
77ed9dac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/HoneypotSettingsController.php
+13
-12
13 additions, 12 deletions
src/HoneypotSettingsController.php
with
13 additions
and
12 deletions
src/HoneypotSettingsController.php
+
13
−
12
View file @
e050fb42
...
...
@@ -9,6 +9,7 @@ namespace Drupal\honeypot;
use
Drupal\Component\Utility\String
;
use
Drupal\Core\Form\FormInterface
;
use
Drupal\Core\Form\FormStateInterface
;
/**
* Returns responses for Honeypot module routes.
...
...
@@ -38,9 +39,9 @@ class HoneypotSettingsController implements FormInterface {
}
/**
*
Implements \Drupal\Core\Form\FormInterface::buildForm().
*
{@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
array
&
$form_state
)
{
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
// Honeypot Configuration.
$form
[
'configuration'
]
=
array
(
'#type'
=>
'fieldset'
,
...
...
@@ -114,7 +115,7 @@ class HoneypotSettingsController implements FormInterface {
// If webform.module enabled, add webforms.
// TODO D8 - See if D8 version of Webform.module still uses this form ID.
if
(
module_e
xists
(
'webform'
))
{
if
(
\Drupal
::
moduleHandler
()
->
moduleE
xists
(
'webform'
))
{
$form
[
'form_settings'
][
'webforms'
]
=
array
(
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Webforms (all)'
),
...
...
@@ -182,37 +183,37 @@ class HoneypotSettingsController implements FormInterface {
}
/**
*
Implements \Drupal\Core\Form\FormInterface::validateForm().
*
{@inheritdoc}
*/
public
function
validateForm
(
array
&
$form
,
array
&
$form_state
)
{
public
function
validateForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
// Make sure the time limit is a positive integer or 0.
$time_limit
=
$form_state
[
'values'
][
'time_limit'
]
;
$time_limit
=
$form_state
->
getValue
(
'time_limit'
)
;
if
((
is_numeric
(
$time_limit
)
&&
$time_limit
>
0
)
||
$time_limit
===
'0'
)
{
if
(
ctype_digit
(
$time_limit
))
{
// Good to go.
}
else
{
form_s
et_e
rror
(
'time_limit'
,
$form_state
,
t
(
"The time limit must be a positive integer or 0."
));
$
form_s
tate
->
setE
rror
(
'time_limit'
,
t
(
"The time limit must be a positive integer or 0."
));
}
}
else
{
form_s
et_e
rror
(
'time_limit'
,
$form_state
,
t
(
"The time limit must be a positive integer or 0."
));
$
form_s
tate
->
setE
rror
(
'time_limit'
,
t
(
"The time limit must be a positive integer or 0."
));
}
// Make sure Honeypot element name only contains A-Z, 0-9.
if
(
!
preg_match
(
"/^[-_a-zA-Z0-9]+$/"
,
$form_state
[
'values'
][
'element_name'
]))
{
form_s
et_e
rror
(
'element_name'
,
$form_state
,
t
(
"The element name cannot contain spaces or other special characters."
));
$
form_s
tate
->
setE
rror
(
'element_name'
,
t
(
"The element name cannot contain spaces or other special characters."
));
}
}
/**
*
Implements \Drupal\Core\Form\FormInterface::submitForm().
*
{@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
array
&
$form_state
)
{
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$config
=
\Drupal
::
config
(
'honeypot.settings'
);
// Save all the non-form-id values from $form_state.
foreach
(
$form_state
[
'v
alues
'
]
as
$key
=>
$value
)
{
foreach
(
$form_state
->
getV
alues
()
as
$key
=>
$value
)
{
if
(
$key
!=
'form_settings'
)
{
$config
->
set
(
$key
,
$value
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment