Last active
December 21, 2017 12:13
-
-
Save sepiariver/a7d6fdc89e2050334086 to your computer and use it in GitHub Desktop.
OnDocFormSave, process MODX Resource content and save to a TV for search indexing.
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 | |
/* | |
* SaveProcessedContent | |
* @author @theboxer | |
* @comments @sepiariver | |
* | |
* GPL, no warranties, etc. | |
* | |
* USAGE: | |
* Enable 'OnDocFormSave' event in Plugin properties, and supply a valid "tvName" value. | |
* | |
*/ | |
// Escape conditions | |
if (($modx->context->get('key') !== 'mgr') || $modx->event->name !== 'OnDocFormSave') return; | |
// Options | |
$tvName = $modx->getOption('tvName', $scriptProperties, 'processedContent', true); | |
$processTemplate = $modx->getOption('processTemplate', $scriptProperties, false); | |
// Save these for later | |
$currentResource = $modx->resource; | |
$currentResourceIdentifier = $modx->resourceIdentifier; | |
$currentElementCache = $modx->elementCache; | |
// Assign values from event parameters | |
$modx->resource = $resource; | |
$modx->resourceIdentifier = $resource->get('id'); | |
$modx->elementCache = array(); | |
// Parse | |
$resourceOutput = ($processTemplate) ? $modx->resource->process() : $modx->resource->content; | |
$modx->parser->processElementTags('', $resourceOutput, true, false, '[[', ']]', array(), $maxIterations); | |
$modx->parser->processElementTags('', $resourceOutput, true, true, '[[', ']]', array(), $maxIterations); | |
// Replace previous values | |
$modx->elementCache = $currentElementCache; | |
$modx->resourceIdentifier = $currentResourceIdentifier; | |
$modx->resource = $currentResource; | |
// Save to TV | |
$resource->setTVValue($tvName, $resourceOutput); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line #31
$modx->resource->content
can be replaced with$modx->resource->process()
than the processed string will contain also processed template, not only content.