• How to modify a chunk in a plugin question#

  • BobRay Reply #1, 1 year, 2 months ago

    Reply
    The code below works fine for resources, but when saving a chunk, the replacements are not made and I get a raft of JSON recursion errors in the error log. The code is essentially the same for both events. Do elements require a different method? I've tried all the ones I can think of (get('snippet') and set('snippet', $value) and data['snippet'] =, $_POST, $scriptProperties) but nothing works.
    <?php
    /* New Code for BadWords Plugin */
    $words = explode(',',$useWords);
    foreach($words as $k => $word) {
        $pattern[$k] = "/\b($word)\b/is";
        $replace[$k] = $replacement;
    }
    unset($word);
    switch ($modx->event->name) {
    
        case 'OnBeforeDocFormSave':
            $resource->setContent(preg_replace($pattern, $replacement, $resource->getContent() ));
            break;
    
        case 'OnBeforeChunkFormSave':
            $chunk->setContent(preg_replace($pattern, $replacement, $chunk->getContent() ));
            break;
    }