/[drupal]/contributions/modules/restapi/restapi_execute.module
ViewVC logotype

Contents of /contributions/modules/restapi/restapi_execute.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Wed Mar 19 20:44:05 2008 UTC (20 months, 1 week ago) by hanenkamp
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +21 -40 lines
File MIME type: text/x-php
* I've rewritten parts of the API to make new modules easier to write (and so that the central REST API module actually helps a bit more).
* I've added a module for Services support and a helper for Login.
* The main REST API module and REST API User module have been tested a bit more.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Provides a module for giving access to submit any form via the
7 * drupal_execute() Form API call.
8 */
9
10 /**
11 * Implements hook_restapi_menu(). Adds the execute callback.
12 */
13 function restapi_execute_restapi_menu($may_cache) {
14 if (!$may_cache) {
15 if (arg(0) == '=' && arg(1) == 'execute' && arg(2)) {
16 $items[] = array(
17 'method' => 'GET',
18 'path' => '=/execute/'.arg(2),
19 'callback' => 'restapi_execute_show_form',
20 'callback arguments' => array(arg(2)),
21 );
22
23 $items[] = array(
24 'method' => 'POST',
25 'path' => '=/execute/'.arg(2),
26 'callback' => 'restapi_execute_submit_form',
27 'callback arguments' => array(arg(2)),
28 );
29 }
30 }
31
32 return $items;
33 }
34
35 /**
36 * Implements hook_restapi_help(). Shows help for GET and POST of a form.
37 */
38 function restapi_execute_restapi_help() {
39 $help['prototypes'][] = array(
40 'method' => 'GET',
41 'path' => '/=/execute/<form-id>',
42 'description' => 'show the form',
43 );
44
45 $help['prototypes'][] = array(
46 'method' => 'POST',
47 'path' => '/=/execute/<form-id>',
48 'description' => 'drupal_execute() the form',
49 );
50
51 return $help;
52 }
53
54 /**
55 * Handles GET /=/execute/<form-id>
56 *
57 * @param $form_id the form ID of the form to show
58 */
59 function restapi_execute_restapi_show_form($data, $form_id) {
60 if (!user_access('access rest api')) {
61 return drupal_access_denied();
62 }
63
64 print restapi_serialize(drupal_get_form($form_id));
65 }
66
67 /**
68 * Handles POST /=/execute/<form-id>
69 *
70 * @param $form_id the form ID of the form to execute
71 */
72 function restapi_execute_restapi_submit_form($data, $form_id) {
73 if (!user_access('access rest api')) {
74 return drupal_access_denied();
75 }
76
77 $result = drupal_execute($form_id, $data);
78 print restapi_serialize($result);
79 }

  ViewVC Help
Powered by ViewVC 1.1.2