| 1 |
/*
|
| 2 |
* connect.module theme functions
|
| 3 |
*
|
| 4 |
* to customize the display of connect forms,
|
| 5 |
* add the phptemplate_connect_form and phptemplate_connect_form_block functions
|
| 6 |
* (below) to your theme's template.php file
|
| 7 |
*
|
| 8 |
* then, to control the display of forms for various types of participant,
|
| 9 |
* add functions called _phptemplate_connect_NODETYPE_DISPLAYTYPE
|
| 10 |
* where NODETYPE is the machine-readable name of the participant node type
|
| 11 |
* and DISPLAYTYPE is 'block' or 'page'
|
| 12 |
* ('block' forms are provided only if you turn on the "Provide a block" function in the campaign page)
|
| 13 |
*
|
| 14 |
* examples are provided for a simple "participant_signon" node type
|
| 15 |
*/
|
| 16 |
|
| 17 |
/* allow theming of connect forms presented on the page */
|
| 18 |
function phptemplate_connect_form($form) {
|
| 19 |
$type = $form['participant_type']['#value'];
|
| 20 |
if (!empty($type)) {
|
| 21 |
$theme_function = "_phptemplate_connect_page_$type";
|
| 22 |
if (function_exists($theme_function)) {
|
| 23 |
$return = call_user_func($theme_function, $form);
|
| 24 |
return $return;
|
| 25 |
}
|
| 26 |
}
|
| 27 |
}
|
| 28 |
|
| 29 |
/* allow theming of connect forms presented in blocks */
|
| 30 |
function phptemplate_connect_form_block($form) {
|
| 31 |
$type = $form['participant_type']['#value'];
|
| 32 |
if (!empty($type)) {
|
| 33 |
$theme_function = "_phptemplate_connect_block_$type";
|
| 34 |
if (function_exists($theme_function)) {
|
| 35 |
$return = call_user_func($theme_function, $form);
|
| 36 |
return $return;
|
| 37 |
}
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
/* connect forms using the participant_email node type */
|
| 42 |
|
| 43 |
// alter form for page display
|
| 44 |
function _phptemplate_connect_page_participant_signon(&$form) {
|
| 45 |
$form['field_contact_name']['0']['value']['#size'] = 50;
|
| 46 |
$form['field_contact_email']['0']['email']['#size'] = 40;
|
| 47 |
$form['field_postalcode']['0']['value']['#size'] = 10;
|
| 48 |
|
| 49 |
// use a common rendering function
|
| 50 |
// one could instead select and render form items here
|
| 51 |
return _phptemplate_connect_participant_signon($form, 'page');
|
| 52 |
}
|
| 53 |
|
| 54 |
// alter form for block display
|
| 55 |
function _phptemplate_connect_block_participant_signon(&$form) {
|
| 56 |
$form['field_contact_name'][0]['value']['#size'] = 20;
|
| 57 |
$form['field_contact_email'][0]['email']['#size'] = 20;
|
| 58 |
$form['field_postalcode']['0']['value']['#size'] = 10;
|
| 59 |
|
| 60 |
// use a common rendering function
|
| 61 |
// one could instead select and render form items here
|
| 62 |
return _phptemplate_connect_participant_signon($form, 'block');
|
| 63 |
}
|
| 64 |
|
| 65 |
// display form
|
| 66 |
function _phptemplate_connect_participant_signon(&$form, $type = 'page') {
|
| 67 |
// default rendering (comment this out to add or remove elements)
|
| 68 |
return drupal_render($form);
|
| 69 |
|
| 70 |
// selected rendering, using template files
|
| 71 |
$form_items = array(
|
| 72 |
'field_contact_name',
|
| 73 |
'field_contact_email',
|
| 74 |
'field_postalcode',
|
| 75 |
'submit',
|
| 76 |
);
|
| 77 |
foreach ($form_items as $item) {
|
| 78 |
$template_variables[$item] = drupal_render($form[$item]);
|
| 79 |
} return _phptemplate_default('connect_' . $type . '_participant_signon', $template_variables);
|
| 80 |
}
|