-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_validation.module
More file actions
44 lines (36 loc) · 1.15 KB
/
custom_validation.module
File metadata and controls
44 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* @file
* Contains custom_validation.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function custom_validation_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the custom_validation module.
case 'help.page.custom_validation':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Just trying out some custom validation of entities') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_entity_type_alter().
*/
function custom_validation_entity_type_alter(array &$entity_types) {
$node = $entity_types['node'];
$node->addConstraint('PreventAnon', []);
}
/**
* Implements hook_entity_bundle_field_info_alter().
*/
function custom_validation_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) {
if ($entity_type->id() == 'node' && $bundle == 'article') {
$fields['field_shirt_size']->addConstraint('ShirtSize', ['sizes' => ['M','L','XL']]);
$fields['field_zip_code']->addConstraint('ZipCode', ['iso' => 'IN']);
}
}