XF 2.3 public:account_preferences: [E_USER_WARNING] Accessed unknown getter on XF:UserOption[1] (src\XF\Mvc\Entity\Entity.php:22 (Add account preference)

Yenxji

Active member
I tried to add adult content to account preferences that could let you choose one show and blur or hide. But It gives errors always when they can't recognize or know where is.


Code:
[HEADING=1]Template errors[/HEADING]
[LIST]
[*]Template public:account_preferences: [E_USER_WARNING] Accessed unknown getter 'elf_mod_nsfw_show' on XF:UserOption[1] (src\XF\Mvc\Entity\Entity.php:224)
[*]Template public:account_preferences: [E_USER_WARNING] Accessed unknown getter 'elf_mod_nsfw_show_with_blur' on XF:UserOption[1] (src\XF\Mvc\Entity\Entity.php:224)
[*]Template public:account_preferences: [E_USER_WARNING] Accessed unknown getter 'elf_mod_nsfw_hide' on XF:UserOption[1] (src\XF\Mvc\Entity\Entity.php:224)
[/LIST]

ELF\XF\Entity\UserOption.php:

Code:
<?php
namespace Elf\XF\Entity;
class UserOption extends XFCP_UserOption
{
    public function updateAdultPreference($preference)
    {
        $this->elf_mod_nsfw_show = false;
        $this->elf_mod_nsfw_show_with_blur = false;
        $this->elf_mod_nsfw_hide = false;
        switch ($preference)
        {
            case 'show':
                $this->elf_mod_nsfw_show = true;
                break;
            case 'blur':
                $this->elf_mod_nsfw_show_with_blur = true;
                break;
            default:
                $this->elf_mod_nsfw_hide = true;
        }
    }
    public static function getStructure(\XF\Mvc\Entity\Structure $structure)
    {
        $structure = parent::getStructure($structure);
        $structure->columns['elf_mod_nsfw_show'] = ['type' => self::BOOL, 'default' => false];
        $structure->columns['elf_mod_nsfw_show_with_blur'] = ['type' => self::BOOL, 'default' => false];
        $structure->columns['elf_mod_nsfw_hide'] = ['type' => self::BOOL, 'default' => true];
        return $structure;
    }
}

Setup.php:

Code:
    protected function getAlters()
    {
        $alters = [];
        $alters['xf_user_option'] = function (Alter $table) {
            $table->addColumn('elf_mod_nsfw_show', 'tinyint', 3)->setDefault(0);
            $table->addColumn('elf_mod_nsfw_show_with_blur', 'tinyint', 3)->setDefault(0);
            $table->addColumn('elf_mod_nsfw_hide', 'tinyint', 3)->setDefault(0);
        };
        return $alters;
    }


    protected function getReverseAlters()
    {
        $alters = [];
        $alters['xf_user_option'] = function (Alter $table) {
            $table->dropColumns([
                'elf_mod_nsfw_show',
                'elf_mod_nsfw_show_with_blur',
                'elf_mod_nsfw_hide',
            ]);
        };
        return $alters;
    }

ELF\XF\Account.php:
Code:
<?php
namespace ELF\XF\Pub\Controller;
class Account extends XFCP_Account
{
    protected function preferencesSaveProcess(\XF\Entity\User $user)
    {
        $form = parent::preferencesSaveProcess($user);
        $input = $this->filter([
            'option' => [
                'adult_content' => 'str'
            ]
        ]);
        $userOption = $user->Option;
        
        // Reset all Adult options first
        $userOption->elf_mod_nsfw_show = false;
        $userOption->elf_mod_nsfw_show_with_blur = false;
        $userOption->elf_mod_nsfw_hide = false;
        // Set based on selection
        switch ($input['option']['adult_content'])
        {
            case 'show':
                $userOption->elf_mod_nsfw_show = true;
                break;
            case 'blur':
                $userOption->elf_mod_nsfw_show_with_blur = true;
                break;
            case 'hide':
            default:
                $userOption->elf_mod_nsfw_hide = true;
                break;
        }
        return $form;
    }
}


Template modifications:

Code:
$0
            
        <xf:radiorow name="option[adult_content]" 
            label="{{ phrase('elf_adult_content') }}">

            <xf:option name="option[adult_content]" value="show" 
                checked="{{ $xf.visitor.Option.elf_mod_nsfw_show }}"
                label="{{ phrase('elf_show_adult_content') }}" />

            <xf:option name="option[adult_content]" value="blur"
                checked="{{ $xf.visitor.Option.elf_mod_nsfw_show_with_blur }}"
                label="{{ phrase('elf_show_adult_content_with_blur') }}"
                hint="{{ phrase('elf_blurred_content_can_be_revealed_on_click') }}" />

            <xf:option name="option[adult_content]" value="hide"
                checked="{{ $xf.visitor.Option.elf_mod_nsfw_hide }}"
                label="{{ phrase('elf_hide_adult_content') }}" />

        </xf:radiorow>
 

Attachments

  • 1737508967000.webp
    1737508967000.webp
    56.1 KB · Views: 9
Have you tried to see if your getStructure was indeed called ? by doing some echoing or dump.
 
Have you tried to see if your getStructure was indeed called ? by doing some echoing or dump.
Yes, OP thread: ELF\XF\Entity\UserOption.php:
PHP:
    public static function getStructure(\XF\Mvc\Entity\Structure $structure)
    {
        $structure = parent::getStructure($structure);
        $structure->columns['elf_mod_nsfw_show'] = ['type' => self::BOOL, 'default' => false];
        $structure->columns['elf_mod_nsfw_show_with_blur'] = ['type' => self::BOOL, 'default' => false];
        $structure->columns['elf_mod_nsfw_hide'] = ['type' => self::BOOL, 'default' => true];
        return $structure;
    }

I can't fix, still not working
 
Back
Top Bottom