XF 2.0 Set Entity Relation to User Options

BoostN

Well-known member
I've added a new column to xf_user_option table called "my_column". I can see that column when I do a {{ dump($user) }} and it's even in the list when I do {{ dump($user.Option) }} in the template. However, when I try to reference that new column via the following syntax I get an error:

HTML:
<hr class="formRowSep" />
{{ dump($user) }}
<xf:checkboxrow>
    <xf:option name="user[my_column]" selected="$user.Option.my_column"
               label="My Column?"/>
</xf:checkboxrow>

Code:
Accessed unknown getter 'my_column' on XF:UserOption[2]

I'm assuming the XF:UserOptions entity doesn't know I have a new column, or does it? How would I tell the 'Option' entity I have a new column? I'm assuming an entity relationship defined in my listener would correct this?

The example in the dev docs does cover a new entity, but really I just want to append my new column to the user entity.
 
Have you created your event listener for entity_structure for the UserOption entity? This page in the docs should cover this :)
 
I did, it's probably not right.

My Class:

PHP:
<?php

namespace BoostN\Test\XF\Admin\Controller;

class User extends XFCP_User
{
    protected function userSaveProcess(\XF\Entity\User $user)
    {
        $form = parent::userSaveProcess($user);

        $input = $this->filter([
            'option' => [
                'my_column' => 'bool'
            ]]);

        $userOptions = $user->getRelationOrDefault('Option');
        file_put_contents('C:\xampp\apache\logs\input2.txt', print_r(array_values($input), TRUE));

        $form->setupEntityInput($userOptions, $input['option']);
        return $form;
    }
}

I'm logging my $input array, and doesn't contain my new value. I'm guessing my event listener isn't correct.

$input dump:
PHP:
Array
(
    [0] => Array
        (
            [my_column] =>
        )

)

Listener:

PHP:
<?php

namespace BoostN\Test;

use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;

class Listener
{
    public static function userEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure)
    {
        $structure->columns['my_column'] = ['type' => Entity::BOOL, 'default' => null];
    }
}

Code Event Listener:

Event: entity_structure
Event Hint: XF\Entity\UserOption
Callback: BoostN\Test\Listener :: userEntityStructure
 
Found the issue, my template was calling the user entity instead of the 'option'.
So,
user[my_column] to option[my_column]
HTML:
<xf:textboxrow name="option[my_column]" value="{$user.Option.my_column}"
               label="Status" />
 
Top Bottom