7
7
* Example work module.
8
8
*/
9
9
10
+ /*
11
+ * Name form with filters.
12
+ */
13
+ define('FORMFILTERAPI_EXAMPLE_FORM_NAME', 'formfilterapi_example');
14
+
10
15
/**
11
16
* Implements hook_menu().
12
17
*/
13
18
function formfilterapi_example_menu() {
14
19
$items['formfilterapi_example'] = array(
15
20
'title' => 'Form filter API',
16
21
'page callback' => 'formfilterapi_example_page',
17
- 'access callback' => TRUE,
22
+ 'access arguments' => array('access content'),
23
+ 'type' => MENU_CALLBACK,
18
24
);
19
25
20
26
return $items;
@@ -24,10 +30,8 @@ function formfilterapi_example_menu() {
24
30
* Example page.
25
31
*/
26
32
function formfilterapi_example_page() {
27
- $name_form = 'formfilterapi_example';
28
- $form = formfilterapi_get_form($name_form);
29
-
30
- $filters = formfilterapi_build_filter_query($name_form);
33
+ $form = formfilterapi_get_form(FORMFILTERAPI_EXAMPLE_FORM_NAME);
34
+ $filters = formfilterapi_build_filter_query(FORMFILTERAPI_EXAMPLE_FORM_NAME);
31
35
32
36
$sql = 'SELECT * FROM {node} ' . $filters['join'] . ' ' . $filters['where'] . ' ORDER BY created DESC';
33
37
$result = db_query($sql, $filters['args']);
@@ -45,28 +49,30 @@ function formfilterapi_example_page() {
45
49
/**
46
50
* Implements hook_formfilterapi().
47
51
*/
48
- function formfilterapi_example_formfilterapi() {
49
- $form['title'] = array(
50
- '#type' => 'textfield',
51
- '#title' => t('Title'),
52
- '#where' => "`title` LIKE '%%%s%%'",
53
- );
54
-
55
- $form['type'] = array(
56
- '#type' => 'select',
57
- '#title' => t('Type'),
58
- '#options' => formfilterapi_example_node_types(),
59
- '#where' => "`type` = '%s'",
60
- );
61
-
62
- $form['user'] = array(
63
- '#type' => 'select',
64
- '#title' => t('User'),
65
- '#options' => formfilterapi_example_users(),
66
- '#where' => "`uid` = %d",
67
- );
68
-
69
- return $form;
52
+ function formfilterapi_example_formfilterapi($op, $session_name, &$sessvals = array()) {
53
+ if ($op == 'filters' && $session_name == FORMFILTERAPI_EXAMPLE_FORM_NAME) {
54
+ $form['title'] = array(
55
+ '#type' => 'textfield',
56
+ '#title' => t('Title'),
57
+ '#where' => "`title` LIKE '%%%s%%'",
58
+ );
59
+
60
+ $form['type'] = array(
61
+ '#type' => 'select',
62
+ '#title' => t('Type'),
63
+ '#options' => formfilterapi_example_node_types(),
64
+ '#where' => "`type` = '%s'",
65
+ );
66
+
67
+ $form['user'] = array(
68
+ '#type' => 'select',
69
+ '#title' => t('User'),
70
+ '#options' => formfilterapi_example_users(),
71
+ '#where' => "`uid` = %d",
72
+ );
73
+
74
+ return $form;
75
+ }
70
76
}
71
77
72
78
/**
0 commit comments