From 85aa1cd57ab37505c4b47115719072406fcf556b Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 11 May 2015 15:52:35 -0400 Subject: [PATCH] Initial Commit of the webform_submit_button module. --- webform_submit_button.info | 6 +++ webform_submit_button.module | 75 +++++++++++++++++++++++++++++ webform_submit_button_component.inc | 47 ++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 webform_submit_button.info create mode 100644 webform_submit_button.module create mode 100644 webform_submit_button_component.inc diff --git a/webform_submit_button.info b/webform_submit_button.info new file mode 100644 index 0000000..f596116 --- /dev/null +++ b/webform_submit_button.info @@ -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 diff --git a/webform_submit_button.module b/webform_submit_button.module new file mode 100644 index 0000000..dd94edb --- /dev/null +++ b/webform_submit_button.module @@ -0,0 +1,75 @@ + 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; + } + } +} diff --git a/webform_submit_button_component.inc b/webform_submit_button_component.inc new file mode 100644 index 0000000..4d2a599 --- /dev/null +++ b/webform_submit_button_component.inc @@ -0,0 +1,47 @@ + '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(), + ); +}