From 447ab8760150b5e8310e8dadf6704020fbc52bae Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 23 Nov 2012 15:09:11 +1300 Subject: [PATCH] BUG Error setting options When setting options that have a NULL value by default (such as imageFieldName) the setConfig function would incorrectly assume the option was not available and would silently ignore. This fix implements a correct option validation mechanism, and throws an error if an incorrect option assignment is attempted. --- code/GridFieldBulkImageUpload.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/code/GridFieldBulkImageUpload.php b/code/GridFieldBulkImageUpload.php index 14941c5..4db5abe 100644 --- a/code/GridFieldBulkImageUpload.php +++ b/code/GridFieldBulkImageUpload.php @@ -53,21 +53,22 @@ class GridFieldBulkImageUpload implements GridField_HTMLProvider, GridField_URLH */ function setConfig ( $reference, $value ) { - if ( isset( $this->config[$reference] ) ) - { - if ( ($reference == 'fieldsClassBlacklist' || $reference == 'fieldsClassBlacklist' || $reference == 'editableFields') && !is_array($value) ) - { - $value = array($value); - } - - //makes sure $forbiddenFieldsClasses are in no matter what - if ( $reference == 'fieldsClassBlacklist' ) - { - $value = array_unique( array_merge($value, $this->forbiddenFieldsClasses) ); - } - - $this->config[$reference] = $value; + if (!key_exists($reference, $this->config) ) { + user_error("Unknown option reference: $reference", E_USER_ERROR); } + + if ( ($reference == 'fieldsClassBlacklist' || $reference == 'fieldsClassBlacklist' || $reference == 'editableFields') && !is_array($value) ) + { + $value = array($value); + } + + //makes sure $forbiddenFieldsClasses are in no matter what + if ( $reference == 'fieldsClassBlacklist' ) + { + $value = array_unique( array_merge($value, $this->forbiddenFieldsClasses) ); + } + + $this->config[$reference] = $value; } /**