XF 2.2 Update custom column not working

emiya

Member
Hi,

I'm currently working on a self-made addon that extends the Userupgrade class. I added a custom input field on the ACP user upgrade edit page (following the Let's Build an Addon guide) and on the step where I need to extend the save process I get an error:
1662984868148.png

This is the code in my foo\addon\XF\Admin\Controller\UserUpgrade.php
PHP:
class UserUpgrade extends XFCP_UserUpgrade
{
    protected function upgradeSaveProcess(\XF\Entity\UserUpgrade $upgrade)
{
    parent::upgradeSaveProcess($upgrade);
    $form = $this->formAction();
    $form->setup(function() use ($upgrade)
    {
        $upgrade->old_costs_amount = $this->filter('old_costs_amount', 'unum');
    });
}
}

This is the code in my Listener.php
PHP:
use XF\Mvc\Entity\Entity;

class Listener
{
    public static function userupgradeEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure)
    {
        $structure->columns['old_costs_amount'] = ['type' => Entity::FLOAT, 'default' => 0, 'max' => 99999999, 'min' => 0];
    }
}

And that's the content of the function in XF\Admin\Controller\UserUpgrade.php
PHP:
protected function upgradeSaveProcess(\XF\Entity\UserUpgrade $upgrade)
    {
        $form = $this->formAction();

        $input = $this->filter([
            'title' => 'str',
            'description' => 'str',
            'display_order' => 'uint',
            'extra_group_ids' => 'array-uint',
            'recurring' => 'bool',
            'cost_amount' => 'unum',
            'cost_currency' => 'str',
            'length_amount' => 'uint',
            'length_unit' => 'string',
            'payment_profile_ids' => 'array-uint',
            'disabled_upgrade_ids' => 'array-uint',
            'can_purchase' => 'bool'
        ]);
        $form->basicEntitySave($upgrade, $input);

        $form->setup(function() use($upgrade)
        {
            if ($this->filter('length_type', 'str') == 'permanent')
            {
                $upgrade->length_amount = 0;
                $upgrade->length_unit = '';
            }
        });

        return $form;
    }

I know that something is messed up and no data is given through the code, but what did I wrong and how can I prevent this in the future?

Kind regards
 
A good friend of mine has solved this problem with the following code:
PHP:
class UserUpgrade extends XFCP_UserUpgrade
{
    protected function upgradeSaveProcess(\XF\Entity\UserUpgrade $upgrade)
    {
        parent::upgradeSaveProcess($upgrade);
        $form = $this->formAction();

        $input = $this->filter([
            'old_costs_amount' => 'unum'
        ]);
        $form->basicEntitySave($upgrade, $input);

/*        $form->setup(function() use($upgrade)
        {
            
        });
*/
        return $form;
    }
}

Is this the correct way to save an input?
 
Top Bottom