-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax_form_entity.callback.inc
More file actions
77 lines (63 loc) · 2.35 KB
/
ajax_form_entity.callback.inc
File metadata and controls
77 lines (63 loc) · 2.35 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
<?php
/**
* Ajax callback for edition (ajax edit link).
*/
function ajax_form_entity_entity_edit_callback($type = 'ajax') {
// TODO : use hook_menu page argument.
$entity_type = arg(3);
$entity_id = arg(4);
$special_id = arg(5);
// Load entity.
$ids[] = $entity_id;
$entity = entity_load($entity_type, $ids);
// TODO : desactivated js compatibility.
if (entity_access('update', $entity_type, $entity[$entity_id])) {
if ($type == 'ajax') {
$form_state['build_info']['args'][] = $entity;
$form['#prefix'] = '<div id="form-closing-wrapper-' . $special_id . '">';
$form['#suffix'] = '</div>';
$form = _ajax_form_entity_build_entity_forms($entity_type, array(), array(), $entity);
$form['#prefix'] .= l(t('Close'), 'ajax-form-entity-cancel/nojs/' . $special_id, array('attributes' => array('class' => array('use-ajax button-cancel'))));
$render_form = drupal_render($form);
$commands = array();
$commands[] = ajax_command_css('#ajax-entity-form-' . $special_id, array('display' => 'none'));
$commands[] = ajax_command_append('#ajax-entity-form-wrapper-' . $special_id, $render_form);
$page = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($page);
}
else {
// TODO : no javascript.
}
}
}
/**
* Ajax callback for deletion (ajax delete link).
*/
function ajax_form_entity_entity_delete_callback($type = 'ajax') {
$entity_type = arg(3);
$entity_id = arg(4);
$special_id = arg(5);
// Load entity to check access.
$ids[] = $entity_id;
$entity = entity_load($entity_type, $ids);
if (entity_access('delete', $entity_type, $entity[$entity_id])) {
if ($type == 'ajax') {
//$message = t('Deleted');
$vars['content'] = 'Deleted';
$message = theme('ajax_form_entity_deleted', $vars);
// For field collection, apply the delete class of Field collection to delete references from host entity.
if ($entity_type == 'field_collection_item') {
$entity[$entity_id]->delete();
}
else {
entity_delete($entity_type, $entity_id);
}
$commands[] = ajax_command_replace('#ajax-entity-form-' . $special_id, $message . theme('status_messages'));
$page = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($page);
}
else {
// TODO : no javascript.
}
}
}