forked from eileenmcnaughton/civicrm_entity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcivicrm_entity_ui_controller.inc
122 lines (104 loc) · 4.04 KB
/
civicrm_entity_ui_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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
class CivicrmEntityUIController extends EntityContentUIController {
public $overviewPagerLimit = 25;
/**
* Always use the same civicrm_entity_form
* @return mixed
*/
public function hook_forms() {
$forms = parent::hook_forms();
foreach ($this->entityInfo['bundles'] as $bundle => $bundle_info) {
if (isset($bundle_info['admin'])) {
$form_id = (!isset($bundle) || $bundle == $this->entityType) ? $this->entityType . '_form' : $this->entityType . '_edit_' . $bundle . '_form';
$forms[$form_id] = array(
'callback' => 'civicrm_entity_form',
);
}
}
return $forms;
}
public function overviewTable($conditions = array()) {
/*
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', $this->entityType);
// Add all conditions to query.
foreach ($conditions as $key => $value) {
$query->propertyCondition($key, $value);
}
if ($this->overviewPagerLimit) {
$query->pager($this->overviewPagerLimit);
}
$results = $query->execute();
$ids = isset($results[$this->entityType]) ? array_keys($results[$this->entityType]) : array();
$entities = $ids ? entity_load($this->entityType, $ids) : array();
ksort($entities);
$rows = array();
foreach ($entities as $entity) {
$rows[] = $this->overviewTableRow($conditions, entity_id($this->entityType, $entity), $entity);
}
$render = array(
'#theme' => 'table',
'#header' => $this->overviewTableHeaders($conditions, $rows),
'#rows' => $rows,
'#empty' => t('None.'),
);
return $render;
*/
}
public function hook_menu() {
/* add menu items for all entities, will display with id as argument to url
* for example goto <drupal_root>/civicrm_contact/1, in the example id =1
*/
$civicrm_entities = _civicrm_entity_enabled_entities();
foreach ($civicrm_entities as $key => $value) {
$dashkey = str_replace('_', '-', $key);
$titlename = ucwords(str_replace('_', ' ', $key));
$items[$dashkey . '/add'] = array(
'title' => 'Create ' . $key,
'page callback' => 'entity_ui_get_form',
'page arguments' => array($key, array(), 'create'),
'access callback' => 'civicrm_entity_op_access',
'access arguments' => array('create', $key),
'type' => MENU_CALLBACK,
);
$items[$dashkey . '/' . '%civicrm_entity_loader'] = array(
//'title' => 'Title',
'title callback' => $key . '_page_title',
'title arguments' => array(1),
'page callback' => 'civicrm_entity_page_view',
'page arguments' => array(1, $key),
'access callback' => 'civicrm_entity_op_access',
'access arguments' => array('view', $key, 1),
'load arguments' => array($key),
);
$items[$dashkey . '/%civicrm_entity_loader/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'load arguments' => array($key),
);
$items[$dashkey . '/' . '%civicrm_entity_loader/edit'] = array(
'title' => 'Edit',
'page callback' => 'entity_ui_get_form',
'page arguments' => array($key, 1, 'edit'),
'access callback' => 'civicrm_entity_op_access',
'access arguments' => array('edit', $key, 1),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'load arguments' => array($key),
);
$items[$dashkey . '/' . '%civicrm_entity_loader/delete'] = array(
'title' => 'Delete',
'page callback' => 'entity_ui_get_form',
'page arguments' => array($key, 1, 'delete'),
'access callback' => 'civicrm_entity_op_access',
'access arguments' => array('delete', $key, 1),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'weight' => 10,
'load arguments' => array($key),
);
}
return $items;
}
}