-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheck.default_properties.inc
83 lines (71 loc) · 2.03 KB
/
eck.default_properties.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
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
<?php
/**
* @file
* Default properties are a grouping of a property and a behavior.
*/
/**
* Default properties form callback.
*/
function eck__default_properties__form($form, &$state, $entity_type) {
// Now we want to display the default properties.
$default_properties = eck_get_default_properties();
$options = array();
foreach ($default_properties as $property_name => $property_info) {
$options[$property_name] = $property_info['label'];
}
$form['default_properties'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#title' => t('Default Properties'),
);
$properties = $entity_type->properties;
$defaults = array();
foreach ($properties as $property => $info) {
$defaults[$property] = $property;
}
$form['default_properties']['#default_value'] = $defaults;
// :S
return $form;
}
/**
* Form submition callback for default properties.
*/
function eck__default_properties__form_submit($form, &$state, $entity_type) {
$entity_type = $state['values']['entity_type'];
$dp = $state['values']['default_properties'];
foreach ($dp as $property => $active) {
if ($active) {
$info = eck_get_default_property($property);
$entity_type->addProperty($property, $info['label'], $info['type'], $info['behavior']);
}
else {
$entity_type->removeProperty($property);
}
}
$state['values']['entity_type'] = $entity_type;
}
/**
* All default properties information.
* @todo combine this and get_default_property().
*
* @return array
* All of the default properties info.
*/
function eck_get_default_properties() {
$default_properties = module_invoke_all('eck_default_properties');
drupal_alter('eck_default_properties', $default_properties);
return $default_properties;
}
/**
* Get a default property by name.
*
* @param string $name
* Default property's name.
*
* @return array
* The default property info.
*/
function eck_get_default_property($name) {
$default_properties = eck_get_default_properties();
return $default_properties[$name];
}