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

XF 2.0 New custom field page

abdfahim

Active member
#1
I have created a new page "accounts/test-fields" to house all the custom fields with new type "test_fields".

But I am not sure how to save the changes of the new page, i.e. write the function testFieldsSaveProcess(). I tried to understand and mimic the XF function accountDetailsSaveProcess(), but miserably failed in both cases.

Code:
namespace AbdFahim\XF\Pub\Controller;

class Account extends XFCP_Account
{
    public function actionTestFields()
    {
        if ($this->isPost())
        {
            $visitor = \XF::visitor();

            if ($visitor->canEditProfile())
            {
                $this->testFieldsSaveProcess($visitor)->run();
            }

            return $this->redirect($this->buildLink('account/test-fields'));
        }
        else
        {
            $view = $this->view('XF:Account\TestFields', 'test_fields');
            return $this->addAccountWrapperParams($view, 'test_fields');
        }
    }

   protected function testFieldsSaveProcess(\XF\Entity\User $visitor)
   {
   
   }

}
 
Last edited:

abdfahim

Active member
#2
Oh I got it done. Though I have no idea if I am doing it correctly, it's visibly working at least!

Please advise if it's not the correct way.

I have no idea why I have do declare that empty variable 'user' => [], but it doesn't work without it.

Code:
protected function testFieldsSaveProcess(\XF\Entity\User $visitor)
    {
        $form = $this->formAction();

        $input = $this->filter([
            'user' => []
        ]);


        $form->basicEntitySave($visitor, $input['user']);

        /** @var \XF\Entity\UserProfile $userProfile */
        $userProfile = $visitor->getRelationOrDefault('Profile');

        $this->customFieldsSaveProcess($form, 'test_fields', $userProfile);

        return $form;


    }