XF 2.0 Thread action not returning correct nodeTree with 'where' condition

Marcel

Active member
PHP:
    public function actionUnarchive(ParameterBag $params)
    {
        $thread = $this->assertViewableThread($params->thread_id);
        $forum = $thread->Forum;
        $currentForumId = $forum->node_id;

        /** @var \XF\Repository\Node $nodeRepo */
        $nodeRepo = $this->repository('XF:Node');
        $nodes = $this->app()->repository('XF:Node')->findNodesForList()->fetch();
        $this->app()->repository('XF:Node')->filterViewable($nodes);
        $viewParams = [
            'thread' => $thread,
            'forum' => $forum,
            'prefixes' => $forum->getUsablePrefixes(),
            'nodeTree' => $nodeRepo->createNodeTree($nodes)
        ];
       return $this->view('XF:Thread\Move', 'thread_move', $viewParams);
    }

That's the function. adding a dump($nodes) to the code, shows me a full list of nodes. Great, and the dropdown menu matches this.
I want to restrict that list of forums to only those that have a particular field set in the xf_node table, so I want to add a 'where' condition to this line

$nodes = $this->app()->repository('XF:Node')->findNodesForList()->where('ut_archive_enabled','=','1')->fetch();

This gives me an 'unknown column' error. Fine. I'll step back a bit and just try and match the node_id for now.

$nodes = $this->app()->repository('XF:Node')->findNodesForList()->where('node_id','=','25')->fetch();
This doesnt throw an error, but the dropdown list on the thread_move template is empty.
However, dump($nodes) shows a restricted list of nodes which is just what I want.
However, it doesn't reflect in the template? The dropdown list is empty.

This may sound like a stupid question (I've only just stepped into rewriting my addons for XF2), but where am I going wrong?
The whole finder/entity/repository is giving my head a bit of a pickle.
 
Last edited:
A tree starts at a root and then follows down branches eventually getting to a leaf (which has no children). If you filter down so that your list only has a leaf -- or more specifically, doesn't have anything that is connected to the root -- you won't have a tree to display.

Essentially, you need the entire path to the nodes you want to be included, otherwise there isn't a way to display the node in question in a tree. To do this, you need to filter after you have the full set of data.

The only other alternative would be to essentially ignore the tree setup of nodes.
 
Thanks Mike. That does make sense. So pull all the nodes into a tree and then cut off the branches and leaves I don't want, based on my criteria?
I did touch on the thought of doing it like that, but it seemed counter-intuitive...security wise.
There's no technical basis for my assumption of course, just ..... logical? Kind of like offering up a full set of keys and then taking back the ones you don't want them to have.

Thanks for the reply, I'll re-evaluate my approach :)
 

Similar threads

Replies
1
Views
1K
Top Bottom