-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathentity_validator.module
More file actions
executable file
·101 lines (90 loc) · 2.54 KB
/
entity_validator.module
File metadata and controls
executable file
·101 lines (90 loc) · 2.54 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* @file
* Programmatically validate entities.
*/
/**
* Implements hook_ctools_plugin_type().
*/
function entity_validator_ctools_plugin_type() {
$plugins['validator'] = array(
'classes' => array('class'),
'process' => 'entity_validator_plugin_process',
);
$plugins['validator']['child plugins'] = TRUE;
return $plugins;
}
/**
* Add defaults values to the validator plugins.
*
* Properties for the "validator" plugin type:
* - name: Set the name based on the entity type and bundle.
* - description: The description of the plugin. Defaults to empty string.
* - options: Array of options needed for the plugin.
*/
function entity_validator_plugin_process(&$plugin, $info) {
$plugin += array(
'description' => '',
'options' => array(),
);
}
/**
* Include CTools plugins and get all entity validator plugins.
*
* @return array
* All plugins relate to entity validator.
*/
function entity_validator_get_validator_plugins() {
ctools_include('plugins');
return ctools_get_plugins('entity_validator', 'validator');
}
/**
* Include CTools plugins and get the specified entity validator plugin.
*
* @param string $plugin_name
* If provided this function only returns the selected plugin.
*
* @return array
* The selected plugin for entity validator.
*/
function entity_validator_get_validator_plugin($plugin_name) {
ctools_include('plugins');
return ctools_get_plugins('entity_validator', 'validator', $plugin_name);
}
/**
* Return the validation handler based on entity type and bundle.
*
* @param $entity_type
* The entity type.
* @param $bundle
* The bundle name.
*
* @return EntityValidateInterface | NULL
* The handler object if found, or NULL.
*/
function entity_validator_get_validator_handler($entity_type, $bundle) {
$plugin_name = $entity_type . '__' . $bundle;
$plugin = entity_validator_get_validator_plugin($plugin_name);
if (!$class = ctools_plugin_load_class('entity_validator', 'validator', $plugin_name, 'class')) {
return NULL;
}
$handler = new $class($plugin);
return $handler;
}
/**
* Return the validation handler for schema validator.
*
* @param $plugin_name
* The name of the validator.
*
* @return ObjectValidateInterface | NULL
* The validator object.
*/
function entity_validator_get_schema_validator($plugin_name) {
$plugin = entity_validator_get_validator_plugin($plugin_name);
if (!$class = ctools_plugin_load_class('entity_validator', 'validator', $plugin_name, 'class')) {
return NULL;
}
$handler = new $class($plugin);
return $handler;
}