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)

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.

Jeff Shields
yaadev.com

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!

Dave Edis - Senior Developer
interactivetools.com