77 * Example work module.
88 */
99
10+ /*
11+ * Name form with filters.
12+ */
13+ define('FORMFILTERAPI_EXAMPLE_FORM_NAME', 'formfilterapi_example');
14+
1015/**
1116 * Implements hook_menu().
1217 */
1318function formfilterapi_example_menu() {
1419 $items['formfilterapi_example'] = array(
1520 'title' => 'Form filter API',
1621 'page callback' => 'formfilterapi_example_page',
17- 'access callback' => TRUE,
22+ 'access arguments' => array('access content'),
23+ 'type' => MENU_CALLBACK,
1824 );
1925
2026 return $items;
@@ -24,10 +30,8 @@ function formfilterapi_example_menu() {
2430 * Example page.
2531 */
2632function 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);
3135
3236 $sql = 'SELECT * FROM {node} ' . $filters['join'] . ' ' . $filters['where'] . ' ORDER BY created DESC';
3337 $result = db_query($sql, $filters['args']);
@@ -45,28 +49,30 @@ function formfilterapi_example_page() {
4549/**
4650 * Implements hook_formfilterapi().
4751 */
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+ }
7076}
7177
7278/**
0 commit comments