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

Strange extending issue...

Discussion in 'XenForo Development Discussions' started by Liam W, Oct 14, 2013.

  1. Liam W

    Liam W Well-Known Member

    Since I tried to change to extending classes to just extending templates, and then changing it back again, the extension on XenForo_ViewPublic_Thread_View doesn't work at all - I know, because I'm outputting debug text to the screen at the beginning of the extension, and it doesn't print out.

    The other 2 view classes I'm extending extend fine, it's just the thread view that doesn't.

    I've no idea how to go about troubleshooting this. Any ideas?

    Liam
     
  2. Daniel Hood

    Daniel Hood Well-Known Member

    You're going to have to post some code and your code event listeners.
     
  3. Liam W

    Liam W Well-Known Member

    Well:

    Event listener function:

    PHP:
    /**
        * Listener to extend classes for drop down.
        * @param string $class
        * @param array $extend
        */
        
    public static function extendClass($class, array &$extend)
        {
            switch (
    $class)
            {
                case 
    "XenForo_ViewPublic_Thread_Create":
                case 
    "XenForo_ViewPublic_Thread_Reply":
                case 
    "XenForo_ViewPublic_Thread_View":
                    
    $extend[] = 'LiamMacros_ViewPublic_Thread_View';
                    break;
            }
           
            return 
    true;
        }
    Extender:

    PHP:
    <?php

    class LiamMacros_ViewPublic_Thread_View extends XFCP_LiamMacros_ViewPublic_Thread_View
    {
        public function 
    renderHtml()
        {
            
    /* Get current userId */
            
    $userid XenForo_Visitor::getUserId();
           
            
    /* @var $model LiamMacros_Model_Macros */
            
    $model XenForo_Model::create('LiamMacros_Model_Macros');
           
            
    /* @var $usermode XenForo_Model_User */
            
    $usermodel XenForo_Model::create('XenForo_Model_User');
           
            
    /* Get user macros */
            
    $usermacros $model->getMacrosForUser($useridtruetrue);
           
            
    /* and admin ones... */
            
    $adminmacros $model->getAdminMacrosForUser($usermodel->getFullUserById($userid), true);
           
            
    $visitor XenForo_Visitor::getInstance();
           
            if (
    is_array($usermodel->getFullUserById($userid)))
            {
                
    $this->_params['macros'] = $model->prepareArrayForDropDown($usermacros$adminmacros);
               
                
    $this->_params['canviewmacros'] = $model->canViewMacros($visitor);
                
    //XenForo_CodeEvent::fire('liammacros_insert_dropdown', array(&$this->_params['macros'], &$this->_params['canviewmacros']));
            
    }
            
    parent::renderHtml();
        }
       
    }

    //class XFCP_LiamMacros_ViewPublic_Thread_View extends XenForo_ViewPublic_Thread_View {}
    The first two classes of the extension extend fine, the final one doesn't...
     
  4. Liam W

    Liam W Well-Known Member

    XenForo_Application::resolveDynamicClass('XenForo_ViewPublic_Thread_View')

    Returns XenForo_ViewPublic_Thread_View...
     
  5. Daniel Hood

    Daniel Hood Well-Known Member

    Do you have an "event hint" set up?
     
  6. Liam W

    Liam W Well-Known Member

    Nope.
     
  7. Daniel Hood

    Daniel Hood Well-Known Member

    Add echo 'class: ' . $class; before $extend[]
     
  8. Liam W

    Liam W Well-Known Member

    class: XenForo_ViewPublic_Thread_View

    On a thread page...
     
  9. Daniel Hood

    Daniel Hood Well-Known Member

    ok erase that and add
    Code:
    $this->_params['test'] = true;
               
    at the top of your renderHtml() function.

    and add
    Code:
    {xen:helper dump, {$test}}
    to your template.
     
  10. Liam W

    Liam W Well-Known Member

    NULL appears on the page.
     
  11. Daniel Hood

    Daniel Hood Well-Known Member

    Ok, odd..
    Try adding
    Code:
    echo 'test'; 
    to the top of that function instead.
    Do you have any other add ons installed that effect that template/renderer?
     
  12. Liam W

    Liam W Well-Known Member

    SNAP!

    After disabling my hide user signatures addon it all worked :p

    Looks like I forgot to call the parent in that addon.... (whoops!)

    Thanks :p
     
  13. Daniel Hood

    Daniel Hood Well-Known Member

    lol. Glad I could help.

    On a side note, may I ask why you have
    PHP:
    if (is_array($usermodel->getFullUserById($userid)))
    I feel like you're adding an extra query when you don't need to.
     
  14. Liam W

    Liam W Well-Known Member

    I think it was to check for a guest or something else, otherwise it would error out. However I could use the vistior instance I have setup instead I guess...
     
  15. Daniel Hood

    Daniel Hood Well-Known Member

    Just figured I'd point out that you most likely don't need that extra query. Yeah, I'd recommend using the visitor instance.
     

Share This Page