Fixed prepare_user_change_log_field code event error?

Liam W

in memoriam 1998-2020
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
 
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
 
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.
 
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.

I moved it down on my test install, and it appeared to work as expected :)
 
Last edited:
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.
 
I'm not changing the event location, but it doesn't try to set the phrase if it's already been set now.
 
Top Bottom