Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fapi_validation
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
fapi_validation
Commits
c19247d4
Commit
c19247d4
authored
5 months ago
by
Viktor Holovachek
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3471145
- Fix all callbacks
parent
c78f5cf7
No related branches found
No related tags found
1 merge request
!6
Issue #3471145 - Fix all callbacks
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fapiv_example/src/Form/SimpleForm.php
+6
-55
6 additions, 55 deletions
fapiv_example/src/Form/SimpleForm.php
src/FapiValidationValidatorsManager.php
+1
-1
1 addition, 1 deletion
src/FapiValidationValidatorsManager.php
src/Validator.php
+3
-3
3 additions, 3 deletions
src/Validator.php
with
10 additions
and
59 deletions
fapiv_example/src/Form/SimpleForm.php
+
6
−
55
View file @
c19247d4
...
...
@@ -4,7 +4,6 @@ namespace Drupal\fapiv_example\Form;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Messenger\MessengerInterface
;
/**
* Implements the SimpleForm form controller.
...
...
@@ -17,43 +16,21 @@ use Drupal\Core\Messenger\MessengerInterface;
class
SimpleForm
extends
FormBase
{
/**
* Protected member variable.
*
* @var \Drupal\Component\Utility\MessengerInterface
* {@inheritdoc}
*/
protected
$messenger
;
/**
* Constructs a new SimpleForm.
*
* @param \Drupal\Component\Utility\MessengerInterface $messenger
* The messenger service.
*/
public
function
__construct
(
MessengerInterface
$messenger
)
{
$this
->
messenger
=
$messenger
;
public
function
getFormId
()
{
return
'fapiv_example_simple_form'
;
}
/**
* Build the simple form.
*
* A build form method constructs an array that defines how markup and
* other form elements are included in an HTML form.
*
* @param array $form
* Default form array structure.
* @param Drupal\Core\Form\FormStateInterface $form_state
* Object containing current form state.
*
* @return array
* The render array defining the elements of the form.
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'title'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Title'
),
'#description'
=>
$this
->
t
(
'Title must be at least 5 characters in length.'
),
'#validators'
=>
[
'length[5, *]'
],
'#validators'
=>
[
'rule'
=>
'length[5, *]'
],
'#filters'
=>
[
'uppercase'
,
'trim'
],
'#required'
=>
TRUE
,
];
...
...
@@ -64,7 +41,6 @@ class SimpleForm extends FormBase {
'#description'
=>
$this
->
t
(
'The Value should be JonhDoe.'
),
'#validators'
=>
[
[
'rule'
=>
'length[7]'
,
'error'
=>
'Wrong name size of field %field.'
],
'custom_validator'
,
],
'#required'
=>
TRUE
,
];
...
...
@@ -86,34 +62,9 @@ class SimpleForm extends FormBase {
}
/**
* Getter method for Form ID.
*
* The form ID is used in implementations of hook_form_alter() to allow other
* modules to alter the render array built by this form controller. it must
* be unique site wide. It normally starts with the providing module's name.
*
* @return string
* The unique ID of the form defined by this class.
*/
public
function
getFormId
()
{
return
'fapiv_example_simple_form'
;
}
/**
* Implements a form submit handler.
*
* The submitForm method is the default method called for any submit elements.
*
* @param array $form
* The render array of the currently built form.
* @param Drupal\Core\Form\FormStateInterface $form_state
* Object describing the current state of the form.
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
/*
* This would normally be replaced by code that actually does something
* with the title.
*/
$title
=
$form_state
->
getValue
(
'title'
);
$this
->
messenger
()
->
addMessage
(
$this
->
t
(
'You specified a title of %title.'
,
[
'%title'
=>
$title
]));
}
...
...
This diff is collapsed.
Click to expand it.
src/FapiValidationValidatorsManager.php
+
1
−
1
View file @
c19247d4
...
...
@@ -112,7 +112,7 @@ class FapiValidationValidatorsManager extends DefaultPluginManager {
return
call_user_func_array
([
$plugin
[
'class'
],
$plugin
[
'error_callback'
]],
[
$validator
,
$element
]);
}
// Plugin defined error message?
elseif
(
$plugin
[
'error_message'
]
!==
NULL
)
{
elseif
(
!
empty
(
$plugin
[
'error_message'
]
)
)
{
$message
=
$plugin
[
'error_message'
];
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/Validator.php
+
3
−
3
View file @
c19247d4
...
...
@@ -68,11 +68,11 @@ class Validator {
private
function
parse
()
{
if
(
is_array
(
$this
->
rawValidator
))
{
if
(
isset
(
$this
->
rawValidator
[
'error'
]))
{
$this
->
error
_m
essage
=
$this
->
rawValidator
[
'error'
];
$this
->
error
M
essage
=
$this
->
rawValidator
[
'error'
];
}
if
(
isset
(
$this
->
rawValidator
[
'error callback'
]))
{
$this
->
error
_c
allback
=
$this
->
rawValidator
[
'error callback'
];
$this
->
error
C
allback
=
$this
->
rawValidator
[
'error callback'
];
}
if
(
!
isset
(
$this
->
rawValidator
[
'rule'
]))
{
...
...
@@ -153,7 +153,7 @@ class Validator {
* Check.
*/
public
function
hasErrorCallbackDefined
()
{
return
$this
->
error
Message
!==
NULL
;
return
$this
->
error
Callback
!==
NULL
;
}
/**
...
...
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