This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from aweingarten/initial-module-creation
Initial Commit of the webform_submit_button module.
- Loading branch information
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name = Webform Submit Button | ||
description = Adds a webform submit button component which can be placed like any other component. | ||
core = 7.x | ||
version = 7.x-1.0 | ||
package = Webform | ||
dependencies[] = webform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* @file | ||
* Webform submit button module. | ||
*/ | ||
|
||
|
||
/** | ||
* Implements hook webform_component_info(). | ||
*/ | ||
function webform_submit_button_webform_component_info() { | ||
$components = array(); | ||
$components['submit_button'] = array( | ||
'label' => t('Submit button'), | ||
'description' => t('Displays Submit Button in the Form as a webform component.'), | ||
'features' => array( | ||
'analysis' => FALSE, | ||
'csv' => FALSE, | ||
'default_value' => FALSE, | ||
'description' => FALSE, | ||
'email' => FALSE, | ||
'required' => FALSE, | ||
'conditional' => FALSE, | ||
'title_display' => FALSE, | ||
'private' => FALSE, | ||
'wrapper_classes' => FALSE, | ||
'css_classes' => FALSE, | ||
), | ||
'file' => 'webform_submit_button_component.inc', | ||
); | ||
|
||
return $components; | ||
} | ||
|
||
/** | ||
* Implements hook_form_alter(). | ||
*/ | ||
function webform_submit_button_form_alter(&$form, &$form_state, $form_id) { | ||
|
||
// We only want to execute this in a very particular case where we are | ||
// rendering a webform for display. There may be a more elegant way to | ||
// detect that case. | ||
if (!isset($form['#node'])) { | ||
return; | ||
} | ||
|
||
$is_webform = $form['#node']->type == 'webform'; | ||
$is_webform_render = isset($form['submitted']); | ||
if (!$is_webform || !$is_webform_render) { | ||
return; | ||
} | ||
|
||
// At this point we know that we are rendering a webform. | ||
foreach ($form['submitted'] as $key => $value) { | ||
$current_component_type = $value['#webform_component']['type']; | ||
|
||
if ($current_component_type == 'submit_button') { | ||
|
||
// Get the weight of the user's submit button component. | ||
$current_weight = $value['#webform_component']['weight']; | ||
|
||
// Apply the weight to the actual webform submit button. | ||
$actions = $form['actions']; | ||
$actions['#weight'] = $current_weight; | ||
|
||
// Move the webform submit button into the position of the | ||
// user's submit button component. Remove the user's component since it | ||
// was really just a placeholder for the real thing. | ||
|
||
unset($form['actions']); | ||
unset($form['submitted'][$key]); | ||
$form['submitted']['submit_button'] = $actions; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Webform Submit Button component. | ||
*/ | ||
|
||
/** | ||
* Implements _webform_render_component(). | ||
* | ||
* This is necessary so that there is a placeholder in the form render array | ||
* where the webform submit button can be moved to. | ||
*/ | ||
function _webform_render_submit_button($component, $value = NULL, $filter = TRUE) { | ||
$wrapper = array( | ||
'#type' => 'container', | ||
'#attributes' => array( | ||
'class' => array('placeholder-for-submit-button'), | ||
), | ||
); | ||
|
||
return $wrapper; | ||
} | ||
|
||
/** | ||
* Implements _webform_edit_component(). | ||
*/ | ||
function _webform_edit_submit_button($component) { | ||
// Force the parent to always be root. | ||
$form['position']['placeholder'] = array( | ||
'#type' => 'hidden', | ||
'#value' => '0', | ||
); | ||
return $form; | ||
} | ||
|
||
|
||
/** | ||
* Implements _webform_defaults_component(). | ||
*/ | ||
function _webform_defaults_submit_button() { | ||
return array( | ||
'name' => '', | ||
'form_key' => NULL, | ||
'extra' => array(), | ||
); | ||
} |