We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53460
    • 69 Posts
    I'm looking at the list for System Events. Is there a way to fire an event when duplicating a document?

    Basically, here's what's going on: Each page is given a unique link_attributes ID when saved (this field is hidden by default so people don't edit it). This is then referenced elsewhere for use with some TVs. But, when I duplicate that page, I get a duplicate link_attributes value which overrides the original when using that in a TV or in the index of my search engine.

    If there is no System Event that I could use to clear the link_attributes field on document duplication, how would I accomplish this?

    Thanks
      • 4172
      • 5,888 Posts
      The Event is OnResourceDuplicate

      you will also need to handle duplicated children in some way. See this one for an example:
      https://github.com/Bruno17/migxmultilang/blob/master/core/components/migxmultilang/elements/plugins/mml_synctranslations.plugin.php#L77
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 53460
        • 69 Posts
        Quote from: Bruno17 at Feb 23, 2018, 06:03 PM
        The Event is OnResourceDuplicate

        you will also need to handle duplicated children in some way. See this one for an example:
        https://github.com/Bruno17/migxmultilang/blob/master/core/components/migxmultilang/elements/plugins/mml_synctranslations.plugin.php#L77

        Thanks, so I installed from the Extras menu and then I reused this code:
        <?php
        if ($modx->event->name != 'OnDocFormSave') {return false;}
        if(($resource->get('template') == 12) || ($resource->get('template') == 28)){
            if(empty($resource->get('link_attributes'))){
                $resource->set('link_attributes', md5($resource->get('id').$resource->get('pagetitle').$resource->get('parent').$resource->get('template')));
                $resource->save();
            }    
        }


        Into this code:
        <?php
        if ($modx->event->name != 'OnResourceDuplicate') {return false;}
        
        if(($resource->get('template') == 12) || ($resource->get('template') == 28)){
            if(!empty($resource->get('link_attributes'))){
                $resource->set('link_attributes', '');
                $resource->save();
            }
        }


        It didn't work...
          • 4172
          • 5,888 Posts
          did you check the System - Event OnResourceDuplicate for your plugin?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 53460
            • 69 Posts
            Sorry, this is the first time I've done anything in plugins for MODX. What does that mean?
              • 53460
              • 69 Posts
              Sorry, I didn't know that tab was event there. LOL

              I did check that but the only thing different now is when I right-click and choose Duplicate, I get the pop-up box to enter new info. But when I click OK, it just hangs there. When I refresh the page, the duplicated page is there but the link_attributes field hasn't been cleared.
                • 4172
                • 5,888 Posts
                there isn't $resource, there is $oldResource and $newResource
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!