XF 2.2 entity_post_save listener

Orit

Active member
Hello
I'm listening to entity_post_save
event hint: XF\Entity\Node

I want to run a code if the node is created/edited in a specific category.

When the node is created directly in the category (1st depth) the code runs fine.
I'm a bit lost at triggering the code when the node is created in child-nodes of the same category.

I thought of using the 'breadcrumb_data' column, but it seems to be generated later, and the data in there is the old data from pre_save.
Am I wrong?
Is there a way to trigger the code in child-nodes too?

Thanks!!
 
I think I got it quite simple, without the breadcrumbs.
This is my code (in case it'll be any help to someone else...)
PHP:
protected static function isNodeInCategory($node, $categoryId)
    {
        // Traverse up the node hierarchy
        while ($node) {
            if ($node->node_id == $categoryId) {
                return true;
            }
            $node = $node->Parent;
        }
        return false;
    }

I then run the code only if self::isNodeInCategory($entity, $myCategoryId) returns true.

I'd really like to know if there is a better or built-in way to do it...
 
Back
Top Bottom