Commit 6338c39b authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon

Perform basic form validation on file browser actions (Bug 1480329)

behatnotneeded: Requires doctoring requests, which Behat can't currently do

Change-Id: I619ab2cf768a4621a77026ed172c01b1c484a99e
parent e10fe1c1
...@@ -391,7 +391,7 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) { ...@@ -391,7 +391,7 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) {
} }
// Process actions that must occur before form validation and // Process filebrowser actions that must occur before normal form validation and
// which can safely occur without affecting the element's value // which can safely occur without affecting the element's value
$result = pieform_element_filebrowser_doupdate($form, $element); $result = pieform_element_filebrowser_doupdate($form, $element);
...@@ -465,12 +465,32 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) { ...@@ -465,12 +465,32 @@ function pieform_element_filebrowser_get_value(Pieform $form, $element) {
} }
/**
* This function handles filebrowser actions, such as uploading files, deleting files, creating folders, etc.
* It piggybacks on the surrounding pieform but bypasses the normal Pieforms validation process.
*
* @param Pieform $form
* @param array $element
* @return mixed
*/
function pieform_element_filebrowser_doupdate(Pieform $form, $element) { function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
require_once('license.php'); require_once('license.php');
$result = null; $result = null;
$prefix = $form->get_name() . '_' . $element['name']; $prefix = $form->get_name() . '_' . $element['name'];
// Since this is executed before normal pieforms validation, we'll redundantly call the validation here
try {
$sesskey = param_variable('sesskey', null);
pieform_validate($form, array('sesskey' => $sesskey));
}
catch (Exception $e) {
return array(
'error' => true,
'message' => $e->getMessage(),
);
}
$delete = param_variable($prefix . '_delete', null); $delete = param_variable($prefix . '_delete', null);
if (is_array($delete)) { if (is_array($delete)) {
$keys = array_keys($delete); $keys = array_keys($delete);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment