-
Notifications
You must be signed in to change notification settings - Fork 4
/
references_dialog.api.php
123 lines (115 loc) · 3.98 KB
/
references_dialog.api.php
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
123
<?php
/**
* @file
* This file contains documentation on hooks provided by this module.
*/
/**
* @defgroup references_dialog API Hooks
* @{
*/
/**
* Define a widget to which you want to attach add, search or edit links.
*
* @return
* An array keyed by the widget you want to attach links to. This array
* should contain the following keys:
* - 'element_type': The type of FAPI element the widget is.
* - 'format': The format in which the data should be inserted as a value
* into the form element. The following patterns are provided, $label, $entity_id and $entity_type.
* - operations: An array of available operations.
* Usually search, edit and add should be provided.
* Each array should contain a callback funciton to render the links and a
* label that will be shown on the widget administration page.
*/
function hook_references_dialog_widgets() {
return array(
'node_reference_autocomplete' => array(
'element_type' => 'textfield',
'format' => '$label [nid: $entity_id]',
'views_query' => 'references_dialog_node_reference_views_query',
'operations' => array(
'search' => array(
'function' => 'references_dialog_get_field_search_links',
'title' => t('Search Dialog'),
),
'edit' => array(
'function' => 'references_dialog_node_reference_edit_link',
'title' => t('Edit dialog'),
),
'add' => array(
'function' => 'references_dialog_node_reference_add_link',
'title' => t('Add dialog'),
),
),
),
);
}
/**
* Alter the widget definitions provided by hook_references_dialog_widgets().
*
* @param $widgets
* The associative array of widget definitions.
*
* @see hook_references_dialog_widgets()
*/
function hook_references_dialog_widgets_alter(&$widgets) {
$search = $widgets['entityreference_autocomplete']['operations']['search'];
unset($widgets['entityreference_autocomplete']['operations']['search']);
$widgets['entityreference_autocomplete']['operations'] = array('search' => $search) + $widgets['entityreference_autocomplete']['operations'];
}
/**
* Provide the admin paths for where different entity types can be edited.
* This is used by references dialog to work properly with the entity reference module.
* @return
* An array keyed by entity type containing the following keys:
* - 'add': Where the admin page is located to add a new entity of this type.
* - 'edit': Where the admin page is located to edit an entity of this type.
* You can use the following replacement patterns: [bundle-sanitized], [entity_id], [bundle]
*/
function hook_references_dialog_entity_admin_paths() {
return array(
'node' => array(
'add' => 'node/add/[bundle-sanitized]',
'edit' => 'node/[entity_id]/edit',
),
);
}
/**
* Return all 'attachables' that can be used together with views. An attachable
* is just a name that the views search reference plugin uses to know what
* to attach itself to. You can define your own attachables if you want to
* use the references dialog search functionality outside of the realm of fields.
*
* @return
* An array keyed by entity and a unique name containing the following:
* - 'label': The label to use in views.
*/
function hook_references_dialog_search_attachables() {
// Return search views attachables for nodes.
return array(
'node' => array(
'mysearchplugin' => array(
'label' => t('A pretty label'),
),
),
);
}
/**
* Allow other modules to alter the link
*
* @param $link
* The link array to be formed by l()
* @param $element
* The element to which the widget is attached
*/
function hook_references_dialog_link_alter(&$link, $element) {
if ($element['#field_name'] == 'field_source') {
// This example adds the query string to prepopulate the form
$link['query'] = [
'edit[field_trasnslations][und][0][nid]' => '[nid:' . $element['#entity']->nid . ']',
];
}
}
/**
* @} End of "addtogroup hooks".
*/