We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8898
    • 181 Posts
    Hi,

    I’d like to write a little plugin that checks and possibly modifies the content of a ressource when it is saved in the Manager (cleaning up after TinyMCE wink).

    Until now I only wrote plugins that modified the output of a page via
    <?php
    if ('OnWebPagePrerender' == $modx->event->name) {
        // Get a reference to the output
        $output = &$modx->resource->_output;
    
        // Modify the output
        $output = doSomethingWithOutput($output);
    }
    
    return;
    ?>

    which worked perfectly.

    Now I tried something like this (the event OnBeforeDocFormSave is checked in the plugin, of course):
    <?php
    if ('OnBeforeDocFormSave' == $modx->event->name) {
        // Get a reference to the content
        $content = &$modx->resource->_content;
    
        // Modify the content
        $content = doSomethingWithContent($content);
    }
    
    return;
    ?>

    But as it seems, the content can’t be referenced this way. Could anybody tell me how to do this correctly?

    Cheers,
    Jan
      This message has been ROT-13 encrypted twice for higher security.
      • 8898
      • 181 Posts
      Okay, I found some time to look into it. Using
      $content = &$resource->_fields['content'];

      it works.

      Unfortunately the content isn’t reloaded automatically, I have to reload it manually to make the changes visible. Maybe I’ll find a solution for this, too... If somebody knows how to achieve this, don’t be shy! wink

      Cheers,
      Jan
        This message has been ROT-13 encrypted twice for higher security.