Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
field_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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
field_validation
Commits
3078b0ec
Commit
3078b0ec
authored
Jul 30, 2023
by
howard ge
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3377623
by g089h515r806: add support for Drupal core's Constraints, add isnull
parent
98ae969b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/schema/field_validation.schema.yml
+11
-0
11 additions, 0 deletions
config/schema/field_validation.schema.yml
src/Plugin/FieldValidationRule/IsNullConstraintFieldValidationRule.php
+71
-0
71 additions, 0 deletions
...eldValidationRule/IsNullConstraintFieldValidationRule.php
with
82 additions
and
0 deletions
config/schema/field_validation.schema.yml
+
11
−
0
View file @
3078b0ec
...
...
@@ -111,3 +111,14 @@ field_validation.rule.email_constraint_rule:
message
:
type
:
string
label
:
'
Message'
field_validation.rule.null_constraint_rule
:
type
:
mapping
label
:
'
IsNull
constraint
validation
rule'
mapping
:
validate_mode
:
type
:
string
label
:
'
Validate
mode'
message
:
type
:
string
label
:
'
Message'
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Plugin/FieldValidationRule/IsNullConstraintFieldValidationRule.php
0 → 100644
+
71
−
0
View file @
3078b0ec
<?php
namespace
Drupal\field_validation\Plugin\FieldValidationRule
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\field_validation
\ConstraintFieldValidationRuleBase
;
use
Drupal\field_validation
\FieldValidationRuleSetInterface
;
/**
* Provides funcationality for EmailFieldValidationRule.
*
* @FieldValidationRule(
* id = "null_constraint_rule",
* label = @Translation("IsNull constraint"),
* description = @Translation("IsNull constraint.")
* )
*/
class
IsNullConstraintFieldValidationRule
extends
ConstraintFieldValidationRuleBase
{
/**
* {@inheritdoc}
*/
public
function
getConstraintName
():
string
{
return
"Null"
;
}
/**
* {@inheritdoc}
*/
public
function
isPropertyConstraint
():
bool
{
return
FALSE
;
}
/**
* {@inheritdoc}
*/
public
function
defaultConfiguration
()
{
return
[
'message'
=>
NULL
,
]
+
parent
::
defaultConfiguration
();
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
=
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
//copied from core.
$message
=
'This value should be null.'
;
$form
[
'message'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Message'
),
'#default_value'
=>
$this
->
configuration
[
'message'
]
??
$message
,
'#maxlength'
=>
255
,
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
$this
->
configuration
[
'message'
]
=
$form_state
->
getValue
(
'message'
);
}
}
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