forked from eileenmcnaughton/civicrm_entity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
civicrm_entity_metadata_controller.inc
54 lines (50 loc) · 1.51 KB
/
civicrm_entity_metadata_controller.inc
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
<?php
/**
* @file
* Provides Entity metadata integration.
*/
/**
* Extend the default CiviCRM membership metadata properties.
*/
class CivicrmEntityMetadataController extends EntityDefaultMetadataController {
/**
* Return a set of properties for an entity based on the schema definition.
*/
protected function convertSchema() {
if (empty($this->info['base table'])) {
return array();
}
return civicrm_entity_metadata_convert_schema($this->info['base table']);
}
}
/**
* Converts schema info for table to property info.
*
* This is based on the CiviCRM get schema function and is a very
* limited implementation.
*
* @param string $table
* The name of the table as used in hook_schema().
*
* @return array
* Property info suitable for hook_entity_property_info().
*/
function civicrm_entity_metadata_convert_schema($table) {
$schema = civicrm_entity_get_schema($table);
$properties = array();
foreach ($schema['fields'] as $name => $info) {
if ($type = _entity_metadata_convert_schema_type($info['type'])) {
$properties[$name] = array(
'type' => $type,
'label' => drupal_ucfirst($name),
'schema field' => $name,
// As we cannot know about any setter access, leave out the setter
// callback. For getting usually no further access callback is needed.
);
if ($info['type'] == 'serial') {
$properties[$name]['validation callback'] = 'entity_metadata_validate_integer_positive';
}
}
}
return $properties;
}