Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved #3439 where using File field limited to upload directory on other site would result in JavaScript error #3452

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions system/ee/language/english/fieldtypes_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@

'file_dnd_create_directory' => 'Create New Directory',

'file_dnd_no_directories' => 'No upload directories available',

'file_dnd_no_directories_desc' => 'This field is limited to upload directory not available for current member and site.',

'file_grid_vertical_layout_title' => 'File Grid layout',

/* Grid */
Expand Down
2 changes: 2 additions & 0 deletions system/ee/legacy/libraries/File_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
*
* @param string $field_name The name of the field
* @param string $data The data stored in the file field
* e.g. {filedir_x}filename.ext

Check failure on line 30 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 30 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* @param string $allowed_file_dirs The allowed file directory
* Either 'all' or ONE directory ID

Check failure on line 32 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 32 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* @param string $content_type The content type allowed.
* Either 'all' or 'image'

Check failure on line 34 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 34 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* @return string Fully rendered file field
*/
public function field($field_name, $data = '', $allowed_file_dirs = 'all', $content_type = 'all', $filebrowser = true, $existing_limit = null)
Expand Down Expand Up @@ -162,11 +162,11 @@
*
* @param string $field_name The name of the field
* @param string $data The data stored in the file field
* e.g. {filedir_x}filename.ext

Check failure on line 165 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 165 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* @param string $allowed_file_dirs The allowed file directory
* Either 'all' or ONE directory ID

Check failure on line 167 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 167 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* @param string $content_type The content type allowed.
* Either 'all' or 'image'

Check failure on line 169 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 169 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* @return string Fully rendered file field
*/
public function dragAndDropField($field_name, $data = '', $allowed_file_dirs = 'all', $content_type = 'all')
Expand Down Expand Up @@ -284,13 +284,13 @@
// If file field is just a file ID
if (! empty($data) && is_numeric($data)) {
$file = ee('Model')->get('File', $data)->with('UploadDestination')->first(true);
}

Check failure on line 287 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Expected 1 space after closing brace; newline found

Check failure on line 287 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Expected 1 space after closing brace; newline found
// If the file field is in the "{file:XX:url}" format
elseif (is_string($data) && preg_match('/^{file\:(\d+)\:url}/', $data, $matches)) {
// Set upload directory ID and file name
$file_id = $matches[1];
$file = ee('Model')->get('File', $file_id)->with('UploadDestination')->first(true);
}

Check failure on line 293 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Expected 1 space after closing brace; newline found

Check failure on line 293 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Expected 1 space after closing brace; newline found
// If the file field is in the "{filedir_n}image.jpg" format
elseif (is_string($data) && preg_match('/^{filedir_(\d+)}/', $data, $matches)) {
// Set upload directory ID and file name
Expand All @@ -311,8 +311,8 @@
/**
* Initialize the file browser given a configuration array and an endpoint url
* @param array $config Associative array containing five different keys and values:
* - publish: set to TRUE if you're on the publish page, optionally

Check failure on line 314 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 314 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* just pass an empty array or none at all for the same behavior

Check failure on line 315 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed

Check failure on line 315 in system/ee/legacy/libraries/File_field.php

View workflow job for this annotation

GitHub Actions / PSR-12 compatibility check

Spaces must be used for alignment; tabs are not allowed
* - trigger: the selector to pass to jQuery to create a trigger for
* the file browser
* - field_name: the field you're operating on. If undefined, it will
Expand Down Expand Up @@ -1007,6 +1007,8 @@
'lang.file_dnd_uploading_to' => lang('file_dnd_uploading_to'),
'lang.file_dnd_upload_new' => lang('file_dnd_upload_new'),
'lang.file_dnd_create_directory' => lang('file_dnd_create_directory'),
'lang.file_dnd_no_directories' => lang('file_dnd_no_directories'),
'lang.file_dnd_no_directories_desc' => lang('file_dnd_no_directories_desc'),

'dragAndDrop.uploadDesinations' => ee('View/Helpers')->normalizedChoices($upload_destinations),
'dragAndDrop.endpoint' => ee('CP/URL')->make('addons/settings/filepicker/ajax-upload')->compile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class DragAndDropUpload extends React.Component {

var directory = this.checkChildDirectory(EE.dragAndDrop.uploadDesinations, directory);

if (typeof(directory) === 'undefined') {
return ' ';
}

return directory.label
}

Expand All @@ -80,6 +84,13 @@ class DragAndDropUpload extends React.Component {
}
} else {
var directory = this.checkChildDirectory(EE.dragAndDrop.uploadDesinations, directory);
if (typeof(directory) === 'undefined') {
return {
upload_location_id: null,
path: '',
directory_id: 0
};
}
if (directory.value == directory.upload_location_id) {
directory.directory_id = 0
} else {
Expand Down Expand Up @@ -544,6 +555,12 @@ class DragAndDropUpload extends React.Component {
subheading = EE.lang.file_dnd_choose_directory_before_uploading
}

if (EE.dragAndDrop.uploadDesinations.length == 0 && this.state.directory != 'all') {
heading = EE.lang.file_dnd_no_directories
subheading = EE.lang.file_dnd_no_directories_desc
this.props.showActionButtons = false;
}

let checkChildren = this.directoryHasChild(this.props.allowedDirectory);
let uploadDirectoriesForDropdown = EE.dragAndDrop.uploadDesinations;
if (typeof(this.props.roleAllowedDirectoryIds) !== 'undefined' && this.props.roleAllowedDirectoryIds.length > 0) {
Expand Down
19 changes: 19 additions & 0 deletions themes/ee/asset/javascript/src/fields/file/drag_and_drop_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ var DragAndDropUpload = /*#__PURE__*/function (_React$Component) {
value: function getDirectoryName(directory) {
if (directory == 'all') return null;
var directory = this.checkChildDirectory(EE.dragAndDrop.uploadDesinations, directory);

if (typeof directory === 'undefined') {
return ' ';
}

return directory.label;
}
}, {
Expand All @@ -309,6 +314,14 @@ var DragAndDropUpload = /*#__PURE__*/function (_React$Component) {
} else {
var directory = this.checkChildDirectory(EE.dragAndDrop.uploadDesinations, directory);

if (typeof directory === 'undefined') {
return {
upload_location_id: null,
path: '',
directory_id: 0
};
}

if (directory.value == directory.upload_location_id) {
directory.directory_id = 0;
} else {
Expand Down Expand Up @@ -628,6 +641,12 @@ var DragAndDropUpload = /*#__PURE__*/function (_React$Component) {
subheading = EE.lang.file_dnd_choose_directory_before_uploading;
}

if (EE.dragAndDrop.uploadDesinations.length == 0 && this.state.directory != 'all') {
heading = EE.lang.file_dnd_no_directories;
subheading = EE.lang.file_dnd_no_directories_desc;
this.props.showActionButtons = false;
}

var checkChildren = this.directoryHasChild(this.props.allowedDirectory);
var uploadDirectoriesForDropdown = EE.dragAndDrop.uploadDesinations;

Expand Down