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

Fixed prepare_user_change_log_field code event error?

Discussion in 'Resolved Bug Reports' started by Liam W, Feb 12, 2014.

  1. Liam W

    Liam W Well-Known Member

    I've been looking into this, and I'm wondering if it's a bug that the code event is fired before the prepareField() method in the helper is called?

    I ask because that helper sets the name to something completely different, overriding the name set when the event is fired...

    I moved the code event fire below the call to prepareField() and it works fine.

    This is on Beta 3...

    Liam
     
  2. Liam W

    Liam W Well-Known Member

    Looks like this is the same in Beta 4.

    Is this how it should be?
     
  3. Chris D

    Chris D XenForo Developer Staff Member

    Probably need to see some of your code and get an idea of what you're trying to do to be sure.
     
  4. Liam W

    Liam W Well-Known Member

    This is the method that the event calls for my addon:

    PHP:
    public static function changeLogField(XenForo_Model_UserChangeLog $logModel, array &$field)
        {
            if (
    $field['field'] == 'api_key')
            {
                
    $phrase = new XenForo_Phrase('liam_xflicense_key');
                
    $field['name'] = $phrase->render();
            }
            else if (
    $field['field'] == 'api_domain')
            {
                
    $phrase = new XenForo_Phrase('liam_xflicense_domain');
                
    $field['name'] = $phrase->render();
            }
        }
    This is the method that calls it:

    PHP:
    public function prepareField(array $field)
        {
            
    XenForo_CodeEvent::fire('prepare_user_change_log_field', array($this, &$field));
           
            
    $field $this->_getHelper()->prepareField($field);
           
            return array(
                
    'field' => $field['field'],
                
    'name' => $field['name'],
                
    'old_value' => $field['old_value'],
                
    'new_value' => $field['new_value'],
            );
        }
    The event is called, however the value of the field variable is changed after the event has been called, completely nullifying changes made in the event.

    Liam
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    Yeah. I can reproduce this. I think you're right. The code event looks like it needs to be fired after the prepare function. But I've not tested that yet.
     
  6. Liam W

    Liam W Well-Known Member

    I moved it down on my test install, and it appeared to work as expected :)
     
    Last edited: Feb 20, 2014
  7. Mike

    Mike XenForo Developer Staff Member

    If it's an open bug report, it's not gone unnoticed. But it doesn't mean it's a bug or it's going to change -- just that there isn't a resolution yet. You can extend the helper class to do whatever you want.
     
    Amaury likes this.
  8. Mike

    Mike XenForo Developer Staff Member

    I'm not changing the event location, but it doesn't try to set the phrase if it's already been set now.
     

Share This Page