Skip to content

Commit

Permalink
Updating Multiple Forms to 7.x-1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mwanberg committed Dec 4, 2018
1 parent bb100d9 commit e0390ee
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
Empty file modified sites/all/modules/contrib/multiform/LICENSE.txt
100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions sites/all/modules/contrib/multiform/multiform.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ files[] = multiform.module
files[] = tests/multiform.test
core = 7.x

; Information added by Drupal.org packaging script on 2014-06-11
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2017-08-10
version = "7.x-1.4"
core = "7.x"
project = "multiform"
datestamp = "1402457628"
datestamp = "1502333050"

53 changes: 40 additions & 13 deletions sites/all/modules/contrib/multiform/multiform.module
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

/**
* @file
* Module file for the multiform module, which creates a forms.
*/

/**
* Returns a form containing a number of other forms.
*
Expand Down Expand Up @@ -41,9 +46,12 @@ function multiform_get_form() {
'#attributes' => array(),
);
// This is where buttons will be collected.
$form['buttons'] = array();
$form['buttons']['#weight'] = 1000;
$form['buttons']['#build_id'] = $build_id;
$form['buttons'] = array(
'#type' => 'actions',
'#build_id' => $build_id,
'#weight' => 1000,
'#attributes' => array(),
);
$form_state_save = array();
$button_names = array();
// The only way to support $_GET would be to accept $form_state. Maybe later.
Expand All @@ -57,7 +65,13 @@ function multiform_get_form() {
// names because the buttons are used in the multiform but their values
// in $_POST (if it exists) needs to be handed down to each form so
// those can recognize the button press.
$name = isset($button_elements['#name']) ? $button_elements['#name'] : 'op';
$name = 'op';
if (is_array($button)) {
$name = isset($button['#name']) ? $button['#name'] : 'op';
}
else {
$name = isset($button_elements['#name']) ? $button_elements['#name'] : 'op';
}
$button_names[$name] = $name;
}
}
Expand Down Expand Up @@ -91,7 +105,10 @@ function multiform_get_form() {
// Build and process this form.
$current_form = drupal_build_form($form_id, $form_state);
// Do not render the <form> tags. Instead we render the <form> as a <div>.
$current_form['#theme_wrappers'] = array('container');
$form_wrapper_index = array_search('form', $current_form['#theme_wrappers']);
if ($form_wrapper_index !== FALSE) {
$current_form['#theme_wrappers'][$form_wrapper_index] = 'container';
}
_multiform_get_form($current_form, $form['buttons'], $index);
// Unset any attributes specifics to form tags.
$disallowed_attributes = array('enctype', 'action', 'method');
Expand All @@ -106,6 +123,9 @@ function multiform_get_form() {
}
}
form_set_cache($build_id, $form['buttons'], $form_state_save);

drupal_alter('multiform_get_form', $form_state_save, $redirect, $all_args);

if (!empty($form_state_save['input'])) {
// We forced $form_state['no_redirect'] to TRUE above, so unset it in order
// to allow the redirection to proceed.
Expand All @@ -130,12 +150,19 @@ function _multiform_get_form(&$element, &$buttons, $form_id) {
$buttons[$element['#value']] = $element;
$element['#access'] = FALSE;
}
// By only changing $element['#name'] form API is not affected but the
// browser will put the element values into _POST where multiform_get_form
// expects them.
elseif (isset($element['#name'])) {
// If the name was op then we want multiform[$form_id][op]. If it was
// foo[bar] then we want multiform[$form_id][foo][bar].
$element['#name'] = "multiform[$form_id]" . preg_replace('/^[^[]+/', '[\0]', $element['#name']);
else {
// By only changing $element['#name'] form API is not affected but the
// browser will put the element values into _POST where multiform_get_form
// expects them.
if (isset($element['#name'])) {
// If the name was op then we want multiform[$form_id][op]. If it was
// foo[bar] then we want multiform[$form_id][foo][bar].
$element['#name'] = "multiform[$form_id]" . preg_replace('/^[^[]+/', '[\0]', $element['#name']);
}
// We repeat this for any $element['#attributes']['name'], which show up in
// the rendering arrays of certain multi-value select elements.
if (isset($element['#attributes']['name'])) {
$element['#attributes']['name'] = "multiform[$form_id]" . preg_replace('/^[^[]+/', '[\0]', $element['#attributes']['name']);
}
}
}
}
6 changes: 3 additions & 3 deletions sites/all/modules/contrib/multiform/tests/multiform.test
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class MultiformTestCase extends DrupalWebTestCase {
$this->assertNoText('test2 field is required.');

// Send first form's required field.
$this->drupalPost(NULL, $first_text, 'save');
$this->assertNoText('multiform_test2_1multiform_test2_submit_button');
$this->drupalPost(NULL, array_merge($first_text,array()), 'save');
$this->assertNoText('multiform_test2_2multiform_test2_submit_button');
$this->assertText('test2 field is required.');

// Send second form's required field.
Expand All @@ -101,4 +101,4 @@ class MultiformTestCase extends DrupalWebTestCase {
$this->assertText('test1 field is required.');
}

}
}
6 changes: 3 additions & 3 deletions sites/all/modules/contrib/multiform/tests/multiform_test.info
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ dependencies[] = multiform
hidden = TRUE

files[] = multiform_test.module
; Information added by Drupal.org packaging script on 2014-06-11
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2017-08-10
version = "7.x-1.4"
core = "7.x"
project = "multiform"
datestamp = "1402457628"
datestamp = "1502333050"

0 comments on commit e0390ee

Please sign in to comment.