-
-
Save sebastian-marinescu/c71615e3a1c146da2bd97b4bad23a60e 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment