Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Initial Commit of the webform_submit_button module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam committed May 11, 2015
1 parent 38dab16 commit 85aa1cd
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webform_submit_button.info
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
75 changes: 75 additions & 0 deletions webform_submit_button.module
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;
}
}
}
47 changes: 47 additions & 0 deletions webform_submit_button_component.inc
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(),
);
}

0 comments on commit 85aa1cd

Please sign in to comment.