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.
-
☆ 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.
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');
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.
-
☆ A M B ☆
- 24,524 Posts
Permission settings have nothing to do with publish status. It would need to be another event altogether.
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.
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.
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.