Not planned Extending user privacy options

Snog

Well-known member
While extending the privacy options for users, I discovered there's no really clean way to do it (or I'm just not awake yet).

In account.php you have this quite normal code:
Code:
$input = $this->filter([
    'user' => [
        'visible' => 'bool',
        'activity_visible' => 'bool'
    ],
    'option' => [
        'show_dob_date' => 'bool',
        'show_dob_year' => 'bool'
    ],
    'privacy' => [
        'allow_view_profile' => 'str',
        'allow_post_profile' => 'str',
        'allow_receive_news_feed' => 'str',
        'allow_send_personal_conversation' => 'str',
        'allow_view_identities' => 'str'
    ]
]);

But immediately after that code is the basicEntitySave for the privacy options. This makes it next to impossible to extend the privacy options without adding another database query, maybe two.

What I suggest is adding this function and calling it rather than using $this->filter directly in the savePrivacyProcess function.
Code:
protected function getPrivacyInput()
{
    return $this->filter([
        'user' => [
            'visible' => 'bool',
            'activity_visible' => 'bool'
        ],
        'option' => [
            'show_dob_date' => 'bool',
            'show_dob_year' => 'bool'
        ],
        'privacy' => [
            'allow_view_profile' => 'str',
            'allow_post_profile' => 'str',
            'allow_receive_news_feed' => 'str',
            'allow_send_personal_conversation' => 'str',
            'allow_view_identities' => 'str'
        ]
    ]);
}

This would make extending the privacy options quite simple by extending the new getPrivacyInput function and adding whatever needs to be added.

There may be other places this same line of thought could be applied. But this is the only one I've found to date.
 
Last edited:
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
FormAction::basicEntitySave() doesn't do the save until the action runs. It's just a wrapper around a common pattern calling setup, validate and save.

If you want to add additional behaviors to the form, you would call the appropriate function any time before it's run() method is called. In this case, you do it by extending the savePrivacyProcess method, call your methods (setup/setupEntityInput) and then return the modified FormAction object.

As such, there aren't really any changes we need to make here to allow you to extend the changes.
 
That's actually my point, savePrivacyProcess function calls the form->complete function. So I must need a heck of a lot more coffee to wake up and see what you're saying. :)
 
Jump into the FormAction::complete() function -- it's not doing what you're suggesting. run() is what you're suggesting and that is called on the return value of the savePrivacyProcess function.
 
Yeah, I finished my coffee and had another look. It's actually pretty simple and I was complicating it.

Grab the form from the parent, do a setupEntityInput and return the form.
 
Top Bottom