Forum
Perch API — how to run collection id if statement for control panel event
Hi,
I'm new to working with APIs so struggling a little, but I've been reading through the docs.
What I would like to do is fire off an event when a certain collection is saved. I'm half way there, so I have something like this
$API->on('collection.publish_item', function(PerchSystemEvent $Event){
However, is it possible to only fire off an event when a certain collection name is saved? something like this:
$API->on('collection.publish_item', function(PerchSystemEvent $Event){
if collection_id = x {
}
Some other questions I have:
- If this is possible, is there some documentation listing what variables I can test for? If not, how do I find out the Perch variables available?
- how do I find out the collection id?
If you inspect the
$Event->subject
property, you should have the collection.Take a look here: https://docs.grabaperch.com/api/events/ it lists the properties of the Event that you can access in your code.
When you say inspect, do you mean do a var dump?
If I do a var dump, I can see that the
CollectionID
is shown but underProtected details
e.g.Does this mean it's not available? If I try to echo out collectionID nothing appears e.g.
echo $Event->collectionID;
Thanks, that gave me a clue to how to get there.
To get the variable I had to do…