• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Which Code Event Listener Listens to Link.php?

James

Well-known member
#1
Which code event listener should I be using to modify the buildAdminLink() function located in library/XenForo/Link.php?

I've created a function to change:
Code:
$outputLink = 'admin.php' . ($append !== '' ? '?' : '') . $append;
to:
Code:
$outputLink = 'someSecretPage.php' . ($append !== '' ? '?' : '') . $append;
But the admin links are still resolving to admin.php rather than someSecretPage.php
 

Lawrence

Well-known member
#2
I'm not sure if there is a more specific one, but you can use load_class_controller to listen for class XenForo_Link being loaded and then extend it.
Code:
<?php

class YourAddon_Listener_LoadClassController
{
        public static function loadClassListener($class, &$extend)
        {

                if ($class == 'XenForo_Link')
                {
                        $extend[] = 'YourAddon_Xxxxxxxxxxxx_ClassName';
                }

        }

}
 

James

Well-known member
#3
OK so my listener:

PHP:
<?php

class James_Listener_AdminLink
{
    public static function extendAdminLink($class, array &$extend)
    {
        if ($class == 'XenForo_Link')
        {
            $extend[] = 'James_Link';
        }
    }
}
That's right, assuming my listener is located in library/James/Listener/AdminLink.php (which it is) and it's extending James_Link, located at library/James/Link.php - however the links are still resolving to admin.php... hmm...

My Link.php file is then extending XFCP_James_Link as it's meant to, using exactly the same buildAdminLink() function except for a different link in the $outputLink variable.
 

James

Well-known member
#5
Thanks Mike. Are there going to be more event listeners added, so that we can override the code that can't currently be overridden?
 

Mike

XenForo developer
Staff member
#6
That class isn't a good candidate as it's called entirely statically and changing the prefix of links isn't really a target. This is the sort of change that works with core changes much more easily.
 

Marcus

Well-known member
#9
On my virtual nodes, in thread_list all threads have a &virtual_node_id=1234. When a user clicks on them, they are redirected to the thread which the user is displayed in the 1234 node (breadcrumbs etc. are all from 1234). The problems is the unread/ action. In ControllerPublic_Thread::actionUnread I had to rewrite XenForo_Link::buildPublicLink('threads', $thread, array('page' => $page, $extraParams)) where $extraParams['virtual_node_id'] = $virtualNodeId;

So actually now I have a 1:1 copy of actionUnread in my addon with only a few changes. But I want to work completely without overwriting a whole function.

I want to listen to buildPublicLink and add $extraParams['virtual_node_id'] = $thread['virtual_node_id]; That would make me so happy :)
 

Marcus

Well-known member
#11
Imagine a religious community

Node1 Christian Forum
Subnode2 Abraham -> its actually a virtual node to Subnode 5
Subnode3 Jesus
Node4 Jewis Forum
Subnode5 Abraham

Users browsing Subnode 2 have this breadcrumb: Node1 > Subnode 2. All threads are from Subnode 5.

You might get a better explanation for this, and there are better examples. My community is a bit complex, so this is a bit of an idea. A virtual node is actually a linkforum that works without the user noticing its a link forum.

Do you have an idea how to make this work without overwriting a whole function?
 
Last edited: