XF 2.0 How can I save the input which was written into a custom display location?

Hello xenforo community!
Wasn't here for a long time but because I've got summer holidays I'm finally able to work on my forum style again..


Problem: I've created a new Display Location for a custom user field (settings in my example). Into this display location I've tried to add a new input Field via the admin cp. Everything seems to work. The Field has the new display location, the display location is setted in the database and it's displayed in my settings. The only problem I have is if I write something into the new field and press the save button, the text which I had wrote into the input field is not getting saved. It's also not getting saved into the database.
(A small gif: )


I think it's because I didn't wrote the field into any saveTypeData or something like this. Sadly I didn't know were I have to change something.

My add-on: (I wanted to add 3 new display locations)
Setup.php:


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');
        });
    }
}

Listener.php:
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)
UserField.php:

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;
    }
}


So far that is my add-on which I've created to get the new display locations. I've also have had to create a class extension in the admin cp:

class extension.PNG

and a code event listener:
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:
Code:
<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}" />



//As I already said: Everything works fine but If I try to save the input which I've written into my new field (in my example First Name) it doesn't get saved.
PS: Here is one picture how a custom field looks like:


user field.PNG

Hopefully there is someone who can help me with this "savedata"
Best regards - Justs
 
Last edited:
#push @DL6 can you probably help me with that save process / what did I forgot? You already helped me sometime ago with something like that..

- Justus
 
Last edited:

S Thomas

Well-known member
The problem rather is that your first post is so bloated, nobody's gonna understand what your actual problem is. Try to reduce the amount of code (or put them into spoilers) and shift the pictures into attachments so anyone looking at your problem gets an idea what your point is.
 
Top