/[drupal]/contributions/modules/formblock/formblock.module
ViewVC logotype

Contents of /contributions/modules/formblock/formblock.module

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


Revision 1.6 - (show annotations) (download) (as text)
Wed Dec 10 01:53:44 2008 UTC (11 months, 2 weeks ago) by mikeyp
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +42 -16 lines
File MIME type: text/x-php
#315139 by David Lesieur - site wide contact form as a block
1 <?php
2 // $Id: formblock.module,v 1.5 2008/05/30 22:27:12 mikeyp Exp $
3
4 /**
5 * Implementation of hook_form_alter().
6 */
7 function formblock_form_alter(&$form, $form_state, $form_id) {
8 if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
9 $options = array(t('Disabled'), t('Enabled'));
10 $form['formblock'] = array(
11 '#type' => 'fieldset',
12 '#title' => t('Form block'),
13 '#weight' => 0,
14 );
15 $form['formblock']['formblock_expose'] = array(
16 '#type' => 'radios',
17 '#title' => t('Enable data entry from a block'),
18 '#default_value' => variable_get('formblock_expose_'. $form['#node_type']->type, 0),
19 '#options' => $options,
20 '#description' => t('Enable this option to make the entry form for this content type available as a block.'),
21 );
22 }
23 }
24
25 /**
26 * Implementation of hook_block().
27 */
28 function formblock_block($op = 'list', $delta = 0, $edit = array()) {
29 switch ($op) {
30 case 'list':
31 $blocks = array();
32 foreach (node_get_types('names') as $type => $name) {
33 if (variable_get('formblock_expose_'. $type, 0)) {
34 $blocks[$type] = array(
35 'info' => t('@name form block', array('@name' => $name)),
36 );
37
38 }
39 }
40 $blocks['user_register'] = array(
41 'info' => t('User registration form'));
42 if (module_exists('contact')) {
43 $blocks['contact_site'] = array(
44 'info' => t('Site-wide contact form'));
45 }
46
47 return $blocks;
48
49 case 'view':
50 switch ($delta) {
51 case 'user_register':
52 global $user;
53 // Don't display the form to logged in users or if registration is disabled
54 if (!$user->uid && variable_get('user_register', 1)) {
55 drupal_add_css(drupal_get_path('module', 'formblock'). '/formblock.css', 'module', 'all');
56 return array(
57 'subject' => t('Create new account'),
58 'content' => drupal_get_form('user_register')
59 );
60 }
61 break;
62
63 case 'contact_site':
64 if (user_access('access site-wide contact form') && module_exists('contact')) {
65 if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
66 $content = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
67 }
68 else {
69 drupal_add_css(drupal_get_path('module', 'formblock'). '/formblock.css', 'module', 'all');
70 module_load_include('inc', 'contact', 'contact.pages');
71 $content = drupal_get_form('contact_mail_page');
72 }
73 return array(
74 'subject' => t('Contact'),
75 'content' => $content,
76 );
77 }
78 break;
79
80 default:
81 return formblock_get_block($delta);
82 }
83 }
84 }
85
86 /**
87 * Generate a block containing a node entry form.
88 */
89 function formblock_get_block($type) {
90 if (node_access('create', $type)) {
91 // Include page handler for node_add()
92 module_load_include('inc', 'node', 'node.pages');
93 // Note title before rendering of form.
94 $title = drupal_get_title();
95 $form = node_add($type);
96 $types = node_get_types('names');
97 // Restore title, which will have been overridden.
98 drupal_set_title($title);
99 return array(
100 'subject' => t('@type form', array('@type' => $types[$type])),
101 'content' => $form,
102 );
103 }
104 }

  ViewVC Help
Powered by ViewVC 1.1.2