Hello, that's a repost because @S Thomas said that my first post is simply to long to understand my problem.

Since the last week I'm trying to add a new display location for some input fields in the account settings location.
I want to add for example a new location for a first name. Everything works fine. I was able to add the new location into the custom user field section and added it to the database. My new field also gets displayed on my website.
The problem which I have is if I press the "save" button after I've changed the first name (In my gif example "Test Name") in the account settings it doesn't get saved. It must be because I've forget to add a save process or something like that for my new display location.


A small gif which shows my problem and a picture which shows the new display locations:
Imgur for the gif

My new display location gets displayed in the custom user field section:
user field.png

PHP:
<?php

namespace DisplayLocation;

use XF\Db\Schema\Alter;
use XF\Db\Schema\Create;

use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;

class Setup extends AbstractSetup
{
    use StepRunnerInstallTrait;
    use StepRunnerUpgradeTrait;
    use StepRunnerUninstallTrait;


        public function installStep1()
    {
        $this->schemaManager()->alterTable('xf_user_field', function(Alter $table)
        {
            $table->changeColumn('display_group')->addValues('extra_space_settings');
        });
    }
        public function installStep2()
    {
        $this->schemaManager()->alterTable('xf_user_field', function(Alter $table)
        {
            $table->changeColumn('display_group')->addValues('left_row_settings');
        });
    }
        public function installStep3()
    {
        $this->schemaManager()->alterTable('xf_user_field', function(Alter $table)
        {
            $table->changeColumn('display_group')->addValues('right_row_settings');
        });
    }

    public function uninstallStep1()
    {
        $db = \XF::db();
        $db->query("UPDATE `xf_user_field` SET `display_group` = 'personal' WHERE `display_group` = 'extra_space_settings'");

        $this->schemaManager()->alterTable('xf_user_field', function(Alter $table)
        {
            $table->changeColumn('display_group')->removeValues('extra_space_settings');
        });
    }
    public function uninstallStep2()
    {
        $db = \XF::db();
        $db->query("UPDATE `xf_user_field` SET `display_group` = 'personal' WHERE `display_group` = 'left_row_settings'");

        $this->schemaManager()->alterTable('xf_user_field', function(Alter $table)
        {
            $table->changeColumn('display_group')->removeValues('left_row_settings');
        });
    }
    public function uninstallStep3()
    {
        $db = \XF::db();
        $db->query("UPDATE `xf_user_field` SET `display_group` = 'personal' WHERE `display_group` = 'right_row_settings'");

        $this->schemaManager()->alterTable('xf_user_field', function(Alter $table)
        {
            $table->changeColumn('display_group')->removeValues('right_row_settings');
        });
    }
}
PHP:
<?php

namespace DisplayLocation;

use XF\Mvc\Entity\Entity;

class Listener
{
    public static function userFieldEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure)
    {
        $structure->columns['display_group']['allowedValues'][] = 'extra_space_settings';
        //print_r($structure);
        //die();
        $structure->columns['display_group']['allowedValues'][] = 'left_row_settings';
        //print_r($structure);
        //die();
        $structure->columns['display_group']['allowedValues'][] = 'right_row_settings';
        //print_r($structure);
        //die();
    }

}
To get it displayed into the admin cp I've also created a new path in my add-on (XF/Repository)
PHP:
<?php

namespace DisplayLocation\XF\Repository;

class UserField extends \XF\Repository\UserField
{
    public function getDisplayGroups()
    {
        $groups = parent::getDisplayGroups();

        $groups['extra_space_settings'] = \XF::phrase('Extra Space');
        $groups['left_row_settings'] = \XF::phrase('Left Row');
        $groups['right_row_settings'] = \XF::phrase('Right Row');

        return $groups;
    }
}
class extension.png
code event listener.png
To get my new display location displayed into my settings template I've added this code into my account_details file:
<xf:macro template="custom_fields_macros" name="custom_fields_edit" arg-type="users" arg-group="extra_space_settings" arg-set="{$xf.visitor.Profile.custom_fields}" />

Hopefully someone can help me with that.
Justus
 
Last edited:

S Thomas

Well-known member
There is no save process extended. Check out the controller which is in charge for the user option page you are loading. There should be something like:
PHP:
$this->filter([array_of_inputs]);
$this->bulkSet(bulkInput); // or something else to set the options
somewhere in the save method. You will need to extend that method, call the parent function, filter your additional input and save that aswell.
 
@S Thomas thank you very much!

Just a small question: If I want to add this "function" to my addon how would it look like?
I've tried to create a new folder path in my addon: DisplayLocation\XF\Pub\Controller
and created a file called Account.php.
PHP:
<?php

namespace DisplayLocation\XF\Pub\Controller;

class Account extends \XF\Pub\Controller\Account
{
    protected function accountDetailsSaveProcess(\XF\Entity\User $visitor)

    {
        $this->customFieldsSaveProcess($form, 'left_row_settings', $userProfile);
        $this->customFieldsSaveProcess($form, 'right_row_settings', $userProfile);       
        $this->customFieldsSaveProcess($form, 'extra_space_settings', $userProfile);

    } 
}

I have to missed anything here because if I make it manually it works...
Thank you very much for your help!


----
BTW manual way: You just have to add this line for example
PHP:
$this->customFieldsSaveProcess($form, 'left_row_settings', $userProfile);

into the src/XF/Pub/Controller/Account.php
below these lines in the protected function accountDetailsSaveProcess

PHP:
$this->customFieldsSaveProcess($form, 'personal', $userProfile);
$this->customFieldsSaveProcess($form, 'contact', $userProfile);

- Justus
 
Last edited:
Top