1. 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?

Discussion in 'XenForo Development Discussions' started by James, May 17, 2011.

  1. James

    James Well-Known Member

    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
     
  2. Lawrence

    Lawrence Well-Known Member

    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 likes this.
  3. James

    James Well-Known Member

    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.
     
  4. Mike

    Mike XenForo Developer Staff Member

    You can't override that code with a listener.
     
    Marcus and James like this.
  5. James

    James Well-Known Member

    Thanks Mike. Are there going to be more event listeners added, so that we can override the code that can't currently be overridden?
     
  6. Mike

    Mike XenForo Developer Staff Member

    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.
     
    James likes this.
  7. Marcus

    Marcus Well-Known Member

    Is there a way to extend XenForo_Link in 1.2?
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    No, its entirely static as Mike stated. What are you attempting to do that you need to extend XenForo_Link?
     
  9. Marcus

    Marcus Well-Known Member

    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 :)
     
  10. Chris D

    Chris D XenForo Developer Staff Member

    Maybe I don't want to ask this question or get into this conversation.

    But why do you have virtual nodes? What do they do?
     
    Jeremy likes this.
  11. Marcus

    Marcus Well-Known Member

    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: Jul 29, 2013

Share This Page