We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4385
    • 372 Posts
    I am trying to limit a plugin from activating for only certain criteria. For example trigger only on a certain template or certain author.

    I can’t seem to get the template of the resource that is being published.

    <?php
    if ($modx->event->name == 'OnDocPublished') {
    
      $resourceId = $scriptProperties['id'];
      $resourceTemplate = $modx->get('template');
      $propertyTemplate = $scriptProperties['template'];
      $resourceTitle = "Resource Id #" . $resourceId . " was published.";
    
    ...
    
    
      DropboxUploader -- Upload files to a Dropbox account.
      DIG -- Dynamic Image Generator
      gus -- Google URL Shortener
      makeQR -- Uses google chart api to make QR codes.
      MODxTweeter -- Update your twitter status on publish.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      As far as I know, the only value passed by that event is the id of the resource. If I’m correct in that, then your code will have to fetch the template that resource is using. It may be as simple as another parameter to the get() function; I’m not familiar with the Revo API.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        In Revo, the resource object is also passed as $resource, so these should work:

        $resourceId = $id;
        $template = $resource->get('template');
        $title = $resource->get'pagetitle');
        


        If that doesn’t work, this should:

        $resourceId = $scriptProperties['id'];
        $template = $scriptProperties['resource']->get('template');
        $title =  $scriptProperties['resource']->get'pagetitle');
        


          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 4385
          • 372 Posts
          Awesome! I went with the first one, it worked. I don’t agree with the logic of OnDocPublished, if the resource’s status has been changed to be viewable than that should trigger OnDocPublished and it doesn’t.



          Quote from: BobRay at Jan 07, 2011, 12:54 AM

          In Revo, the resource object is also passed as $resource, so these should work:

          $resourceId = $id;
          $template = $resource->get('template');
          $title = $resource->get('pagetitle');
          


            DropboxUploader -- Upload files to a Dropbox account.
            DIG -- Dynamic Image Generator
            gus -- Google URL Shortener
            makeQR -- Uses google chart api to make QR codes.
            MODxTweeter -- Update your twitter status on publish.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Permission settings have nothing to do with publish status. It would need to be another event altogether.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 4385
              • 372 Posts
              I was over simplifying, I wasn’t talking about permissions.

              When I create a new resource and check off the publish checkbox. It does not trigger OnDocPublished. Only after the document is saved.

              Maybe OnDocFormSave would be more accurate for what I want, but what if it isn’t published.
                DropboxUploader -- Upload files to a Dropbox account.
                DIG -- Dynamic Image Generator
                gus -- Google URL Shortener
                makeQR -- Uses google chart api to make QR codes.
                MODxTweeter -- Update your twitter status on publish.
                • 3749
                • 24,544 Posts
                I agree that the resource/create processor should trigger OnDocPublished if the published status is set. You could file that as an improvement request.
                I think that resource/update does that already, but I’m not sure.

                I also think it might be good to have an OnResourceCreate event invoked in the resource/create processor.

                In the meantime, I think you could have a plugin that listens to OnBeforeDocFormSave, checks $resource->isNew(), and $resource->get(’published’) and acts accordingly.

                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 4385
                  • 372 Posts
                  Quote from: BobRay at Jan 07, 2011, 05:55 PM

                  In the meantime, I think you could have a plugin that listens to OnBeforeDocFormSave, checks $resource->isNew(), and $resource->get(’published’) and acts accordingly.

                  Great idea! thanks
                    DropboxUploader -- Upload files to a Dropbox account.
                    DIG -- Dynamic Image Generator
                    gus -- Google URL Shortener
                    makeQR -- Uses google chart api to make QR codes.
                    MODxTweeter -- Update your twitter status on publish.