XF 2.2 Getting new node ID in saveTypeData when creating new node?

cmpe

Active member
I am extending \XF\Admin\Controller\Forum in my addon with a one-to-one relationship between a Item entity and node. I have the relationship defined in both my custom entity as well as the node through nodeEntityStructure in the listener.

When I extend saveTypeData() in \XF\Admin\Controller\Forum - I am having trouble figuring out how I can find the node ID so that I can save that in the Item entity table.

This is what I have:

Code:
    protected function saveTypeData(FormAction $form, \XF\Entity\Node $node, \XF\Entity\AbstractNode $data)
    {
        parent::saveTypeData($form, $node, $data);

        $form->setup(function() use ($data, $node)
        {
                // process $this->filter here
        });

        // Shouldn't the node ID be available here?
        if ($node->isInsert()) {
            var_dump($node->node_id);
            exit;
        }
 
(well... as it often happens, as SOON as I post here I get an idea to try...)

Was looking at FormAction.php to try to better understand the mechanics of how that worked and realized complete method gets called last.

So adding this to my saveTypeData worked:
Code:
        if ($data->isInsert()) {
            $form->complete(function() use($data, $itemId)
            {
                $item = $this->repository('Cmpe\Class:Item')->findItemById($itemId);
                $item->fastUpdate('node_id', $data->node_id);
            });
        }
 
Top Bottom