froala / wysiwyg-editor-php-sdk

PHP SDK to ease the integration of Froala WYSIWYG Editor on server side.
https://www.froala.com/wysiwyg-editor
MIT License
40 stars 26 forks source link

Array merge fix in File.php #10

Closed bleutzinn closed 7 years ago

bleutzinn commented 7 years ago

Changed array_merge() to array_merge_recursive() to properly merge the two multidimensional arrays. To prevent that fieldname becomes an array the options parameter if used in the call to FroalaEditor_File::upload() should only contain the validation array. For example:

        $options = array(
            //'fieldname' => 'file',
            'validation' => array(
                'allowedExts' => array('csv', 'docx', 'zip'),
                'allowedMimeTypes' => array('text/csv', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip')
            )
        );
        $response = FroalaEditor_File::upload($target_dir, $options);
bleutzinn commented 7 years ago

BTW, obviously the same goes for the upload() function in the Image.php file. Thanks, Ron

florinpopescu commented 7 years ago

@bleutzinn Thanks! 👍

florinpopescu commented 7 years ago

@bleutzinn Actually, I want the options to fallback on the default ones if they are missing or to override the default ones if they are present. If you want, for example, that allowedExts to be array('csv', 'docx', 'zip') concatenated with the default ones you could do like this:

'allowedExts' => array_merge_recursive(array('csv', 'docx', 'zip'), FroalaEditor_File::$defaultUploadOptions['validation']['allowedExts'])

Moreover, if I use array_merge_recursive, an user cannot override fieldname option.

I reverted to array_merge. Please tell me if I am missing something.

Thanks a lot, Florin

bleutzinn commented 7 years ago

The documentation states in upload ($fileRoute, $options) the parameter $options: "This parameter is optional. It can be used to pass custom options for the image upload."

I interpreted that as "allows to specify additional options". In fact the current code with array_merge() works as you described: when $options is used, it completely replaces and overrides the default options.

Sorry for the false alarm!