This solved a problem I had. I thought it might help others.
I asked AI: In Backdrop CMS, I have enabled image uploading for the CKEditor 5 in the "Body" section of a content type where the text format designated is for use by non-admin authenticated users. The problem is I do not want non-admin authenticated users to be able to "Select from Library," yet that option appears to non-admin authenticated users. I only want them to be able to upload files. I also have a separate image field that is part of the content type in question and it has a setting to enable or not enable the image browser. How do I get the "Select from Library" option removed from the image upload screen so it won't show up for non-admin authenticated users?
AI said: To hide the library option conditionally based on the content type or user role, you can use a preprocess hook in your active theme's template.php file to inject a targeted CSS stylesheet or inline script only when that specific form is viewed by non-admin users.
Add the following code snippet to your theme's template.php file:
/**
* Implements hook_form_BASE_FORM_ID_alter() for node_form.
*/
function YOUR_THEME_NAME_form_node_form_alter(&$form, &$form_state, $form_id) {
// Target the permaculture_spotlight content type form
if (isset($form['#node']) && $form['#node']->type == 'permaculture_spotlight') {
// Check if the current user is not an administrator
if (!user_has_role('administrator')) {
// Attach a custom CSS file to hide the library button
$form['#attached']['css'][] = backdrop_get_path('theme', 'YOUR_THEME_NAME') . '/css/hide-editor-library.css';
}
}
}
Make sure to replace YOUR_THEME_NAME in both places with your actual active theme's machine name (e.g., basis or whatever your custom theme is named).
Then, create a small CSS file in your theme's css/ directory named hide-editor-library.css containing:
CSS
.editor-image-library,
.editor-image-toggle:nth-child(2) {
display: none !important;
}
Recent comments
Thanks!! Easiest for me to just give permission for anon users to see the admin theme. That worked. It's just for this one page.
Link field in a Content Type is malformed for annonymous user- Permission issue?
It looks like the screenshot of what you show it should look like is the admin theme whereas what they see is the front end theme. By default, such users won't have permissions to see the...
Link field in a Content Type is malformed for annonymous user- Permission issue?
I've added a new recipe. The recipe has no PHP code. It has two module dependencies (one of those depends on another contrib module and both depend on core modules that are normally enabled)...
The Future of Configuration Recipes for Backdrop CMS
well @herb I cannot believe it, but the webform module was there in modules on the disc, but missing in the listed modules, so I delete the module folder, and downloaded it again. Then...
My Webform Worksheets have disappeared
The only thing I can think of is to make sure Webform module is enabled and that the content type that needs to contain the webforms has Webform enabled for it. Edit the content type and make...
My Webform Worksheets have disappeared