-
-
Save Burick/2c8f3e9c1724153384b10d052872beb5 to your computer and use it in GitHub Desktop.
Scope ContentBlocks (modmore's premium plugin for MODX) to specific templates
This file contains hidden or 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 | |
$eventName = $modx->event->name; | |
switch($eventName) { | |
case 'OnDocFormPrerender': | |
if (!is_object($resource)) { // prevents bad error when user doesn't have perms to resource | |
$modx->log(modX::LOG_LEVEL_ERROR, '[ContentBlocks Templates] No Resource Object on line: ' . __LINE__); | |
return; | |
} | |
// a system setting must be created with the key 'contentblocks.enabled_template_ids' | |
$enabledTemplates = array_map('trim', explode(',', $modx->getOption('contentblocks.enabled_template_ids'))); | |
$forced = $modx->getOption('force_disable', $scriptProperties, 0); | |
if ($forced && !(in_array($resource->get('template'), $enabledTemplates))) { | |
$resource->setProperty('_isContentBlocks', false, 'contentblocks'); | |
$resource->save(); | |
break; | |
} | |
$isContentBlocks = $resource->getProperty('_isContentBlocks', 'contentblocks', null); | |
if ($isContentBlocks !== true) { | |
$disabled = true; | |
if (in_array($resource->get('template'), $enabledTemplates)) $disabled = false; | |
if ($disabled) { | |
$resource->setProperty('_isContentBlocks', false, 'contentblocks'); | |
$resource->save(); | |
} | |
} | |
break; | |
default: | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment