-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheck_shared_entities.module
87 lines (74 loc) · 2.53 KB
/
eck_shared_entities.module
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
<?php
/**
* Implements hook_ctools_plugin_directory().
*/
function eck_shared_entities_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'eck' && $plugin_type == 'property_behavior') {
return 'plugins/eck/' . $plugin_type;
}
if ($owner == 'entityreference' && $plugin_type == 'selection') {
return 'plugins/entityreference/' . $plugin_type;
}
}
/**
* Implements hook_permission().
*/
function eck_shared_entities_permission() {
$permissions = array(
'edit share flag for all entities' => array(
'title' => t('Can edit share flag for all entities'),
'description' => t('Allow the user to mark entities of all types as shared.'),
),
);
foreach (EntityType::loadAll() as $entity_type) {
if (isset($entity_type->properties['shared'])) {
foreach (Bundle::loadByEntityType($entity_type) as $bundle) {
$permissions += array(
'edit share flag for ' . $entity_type->name . ' ' . $bundle->name . ' entities' => array(
'title' => t('Can edit share flag for ' . $bundle->label . ' entities'),
'description' => t('Allow the user to mark ' . $bundle->label . ' (' . $entity_type->label . ') entities as shared.'),
),
);
}
}
}
return $permissions;
}
/**
* Implements hook_eck_default_properties().
*/
function eck_shared_entities_eck_default_properties() {
$default_properties = array();
$default_properties['shared'] = array(
'label' => 'Shared Entity',
'type' => 'integer',
'behavior' => 'shared_entity',
);
$default_properties['shared_title'] = array(
'label' => 'Shared Entity Title',
'type' => 'text',
'behavior' => 'shared_entity_title',
);
return $default_properties;
}
/**
* Implements hook_query_TAG_alter().
*/
function eck_shared_entities_query_shared_entities_alter(QueryAlterableInterface $query) {
$or_properties = array('title', 'shared_title');
$filter_condition = db_or();
$match = $query->getMetaData('match');
$match_operator = $query->getMetaData('match_operator');
$entity_type = $query->getMetaData('entityreference_selection_handler')->entity_type;
$entity_info = entity_get_info($entity_type);
$condition_value = $match;
$condition_operator = '=';
if ($match_operator == 'CONTAINS') {
$condition_value = '%' . $match . '%';
$condition_operator = 'LIKE';
}
foreach ($or_properties as $or_property) {
$filter_condition->condition($entity_info['base_table'] . $or_property, $condition_value, $condition_operator);
}
$query->condition($filter_condition);
}