BUG: tinymce field can't use media library image CMSB 3.82
3 posts by 2 authors in: Forums > CMS Builder
Last Post: Yesterday at 1:42pm (RSS)
By kitsguru - January 27
I was trying to use an image from the media library in the wysiwyg editor. This was previously allowed.
In the cmsb/lib/media_functions.php I discovered these lines of code:
// Validate upload field exists and user has access
$fieldName = request('fieldName');
$uploadFields = Schema::fields($GLOBALS['tableName'], 'upload');
$uploadFieldSchema = $uploadFields[$fieldName] ?? null;
match (true) {
empty($uploadFieldSchema) => die("Invalid upload field: $fieldName"),
!userHasFieldAccess($uploadFieldSchema) => die("No access to field: $fieldName"),
default => null,
};
This issue is that the tinymce field is not type upload but mediumtext.
yaadev.com
By Dave - Friday at 4:11pm
Hi Jeff,
Great find, thanks for reporting that.
We'll have that patched in the next beta and here's some updated code if you want to try it now:
// Validate field exists (upload or wysiwyg with allowUploads) and user has access
$fieldName = request('fieldName');
$fieldSchema = Schema::fields($GLOBALS['tableName'])[$fieldName] ?? null;
$canUpload = $fieldSchema && ($fieldSchema['type'] === 'upload' || ($fieldSchema['type'] === 'wysiwyg' && !empty($fieldSchema['allowUploads'])));
match (true) {
empty($fieldSchema) => die("Invalid field: $fieldName"),
!$canUpload => die("Field doesn't allow uploads: $fieldName"),
!userHasFieldAccess($fieldSchema) => die("No access to field: $fieldName"),
default => null,
};
Let me know if you run into any other issues. Thanks!
interactivetools.com
That didn't work and actually threw another error
Error: Error inserting row.
mysqli_sql_exception(1364): Field 'filePath' doesn't have a default value
Last SQL query (visible to admins only):
INSERT INTO `cmsb_uploads` SET `createdTime` = NOW(), `tableName` = "blog", `fieldName` = "content", `recordNum` = "6", `mediaNum` = 36, `preSaveTempId` = "", `order` = 1769895591, `width` = 0, `height` = 0, `thumbWidth` = 0, `thumbHeight` = 0, `thumbWidth2` = 0, `thumbHeight2` = 0, `thumbWidth3` = 0, `thumbHeight3` = 0, `thumbWidth4` = 0, `thumbHeight4` = 0 in /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:363 [Admin View]
Backtrace:
#0 Script started at /Volumes/J/@projects/yaaws5/html/www/cmsb/admin.php:0
#1 require() at /Volumes/J/@projects/yaaws5/html/www/cmsb/admin.php:81
#2 media_addMediaAjax() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/menus/default/actionHandler.php:98
#3 Itools\ZenDB\DB::insert() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/media_functions.php:381
#4 Itools\ZenDB\DB->fetchResultSet() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:360
#5 Itools\ZenDB\MysqliWrapper->query() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:1011
#6 mysqli->query() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/MysqliWrapper.php:90
#7 mysqli_sql_exception(1364) thrown at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/MysqliWrapper.php:90
#8 Itools\ZenDB\DBException(1364) thrown at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:363
yaadev.com