• 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?

Liam W

Well-known member
#1
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
 

Liam W

Well-known member
#4
Probably need to see some of your code and get an idea of what you're trying to do to be sure.
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
 

Chris D

XenForo developer
Staff member
#5
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.
 

Mike

XenForo developer
Staff member
#7
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.
 

Mike

XenForo developer
Staff member
#8
I'm not changing the event location, but it doesn't try to set the phrase if it's already been set now.