Skip to content
Snippets Groups Projects
Commit 3078b0ec authored by howard ge's avatar howard ge
Browse files

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
......@@ -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
<?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');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment