Last active
December 30, 2021 22:49
-
-
Save jonleverrier/5964596e3bbc8f15a4f305185762eae6 to your computer and use it in GitHub Desktop.
This MODX plugin hides certain Content Blocks buttons from a specific MODX user group. It also disables the drag and drop functionality, so that you can provide some users with a more locked down version of Content Blocks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Content Blocks cbContentEditor Plugin | |
* | |
* This plugin hides certain CB buttons from certain MODX user groups | |
* and disables the drag and drop functionality, so that you can provide | |
* some clients with a more locked down version of CB. | |
* | |
* I would suggest setting up CB templates and defaults in the CB component manager, | |
* so that predefined layouts are loaded automatically when a new resource is created. | |
* It is also recommended that you hide the main content area on "resource/create" using form | |
* customisation, other wise when a user creates a new page, they will be able to delete blocks | |
* and use drag & drop, because no Resource ID has been defined yet (this only happens on save). | |
* | |
* Tested on: MODX 2.6.1, Content Blocks | |
* | |
* Events: OnDocFormPrerender | |
* | |
* @author Jon Leverrier <[email protected]> | |
* | |
*/ | |
switch ($modx->event->name) { | |
// load on system event OnDocFormPrerender | |
case 'OnDocFormPrerender': | |
// get the current resource ID | |
$resource = $modx->resource; | |
// for newly created resources, there will be no ID until the page is saved. So if there | |
// is no ID, stop here... | |
if (!$resource) { | |
return; | |
} | |
// check to see if CB is enabled on a resource | |
$isContentBlocks = $resource->getProperty('_isContentBlocks', 'contentblocks', null); | |
// only load for a specific user group and if CB is enabled on the resource | |
if ($modx->user->isMember('Client Web Editor') && $isContentBlocks = true) { | |
// load custom script to prevent drag and drop feature in CB | |
// (need to find a better way todo this) | |
$modx->regClientStartupHTMLBlock(' | |
<script> | |
jQuery(function($) { | |
var checkCB = setInterval(function() { | |
if (ContentBlocks.initialized) { | |
$("#contentblocks .contentblocks-field-wrap").addClass("prevent-drag"); | |
clearInterval(checkCB); | |
} | |
}, 50); | |
}); | |
</script> | |
'); | |
// remove certain buttons from the CB interface | |
$modx->controller->addHTML(' | |
<style> | |
.contentblocks-field-delete, | |
.contentblocks-add-block, | |
.contentblocks-add-layout, | |
.contentblocks-layout-menu, | |
.contentblocks-layout-move-up, | |
.contentblocks-layout-move-down, | |
.contentblocks-add-content-here, | |
.contentblocks-layout-settings, | |
.contentblocks-field-gallery-url, | |
.contentblocks-field-upload, | |
.contentblocks-field-image-url { | |
display: none !important; | |
} | |
</style> | |
'); | |
} else{ | |
// if the check fails, do nothing | |
return; | |
} | |
break; | |
} |
Hi @jonleverrier - thanks a lot for your fast reply and sorry for not answering earlier.
I just realized, that the plugin works as it should, but can't - up to now - fulfill one respectively two of my last following open wishes:
- Option to disable the drag&drop image upload
- Option to hide the text „or drop images here“ (unfortunately this text is not wrapped with a tag)
I will also ask for the option in this post...
https://forum.modmore.com/t/option-to-disable-the-drag-drop-image-upload-and-upload-from-url/699
... , but maybe someone has already extended this nice plugin or has a useful hint?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @inreti-sb - I've not used MODX for a while, so might not be much help.
I would check:
#contentblocks .contentblocks-field-wrap
exist in the latest version of CB? If yes;.prevent-drag
to#contentblocks .contentblocks-field-wrap
via your browser console does it prevent drag and drop? If yes, adjust the timeout value on line 48. If no;.prevent-drag
was removed and if there is a new way to prevent drag and drop - the plugin worked at the time I wrote it!