Scandal
Well-known member
Hello all!
I need to modify the user title of some accounts, in all locations of the forum (main user profiles, user profiles popup, thread view - postbits etc).
I don't want to save or modify something in the database. Just to return specific titles in case my_field == true (see below) and user_state == 'disabled'. Just show them on the end user / visitor.
I have apply a new User Entity field via my own addon (let's say it my_field). This is on the entity structure event listener:
I tried both following ways but with not 100% succeed.
A. Via a getter on User Entity. I applied this getter on event listener:
Then a class extension (XFCP_User Entity) with this method:
B. Via a class extension of \XF\Template\Templater.php with method:
For some reason, in some cases the above is not working as expected. It seems that there are cases that the code is not running.
I want to bypass any other addon / class extension and apply the correct titles ('A' or 'B'). It is for a small amount of accounts.
Any idea?
I need to modify the user title of some accounts, in all locations of the forum (main user profiles, user profiles popup, thread view - postbits etc).
I don't want to save or modify something in the database. Just to return specific titles in case my_field == true (see below) and user_state == 'disabled'. Just show them on the end user / visitor.
I have apply a new User Entity field via my own addon (let's say it my_field). This is on the entity structure event listener:
PHP:
$structure->columns['my_field'] = ['type' => Entity::BOOL, 'default' => 0];
I tried both following ways but with not 100% succeed.
A. Via a getter on User Entity. I applied this getter on event listener:
PHP:
$structure->getters['custom_title'] = '';
PHP:
public function getCustomTitle()
{
if ($this->my_field == 1 && $this->user_state == 'disabled') // or true instead of "1"
{
return 'A';
}
if ($this->user_state == 'disabled')
{
return 'B';
}
}
PHP:
public function fnUserTitle($templater, &$escape, $user, $withBanner = false, $attributes = [])
{
$main_reply = parent::fnUserTitle($templater, $escape, $user, $withBanner, $attributes);
if ($user->my_field == true && $user->user_state == 'disabled')
{
$userTitle = 'A';
}
else if ($user->user_state == 'disabled')
{
$userTitle = 'B';
}
if ($user->my_field == true || $user->user_state == 'disabled')
{
$class = $this->processAttributeToRaw($attributes, 'class', ' %s', true);
if (!empty($attributes['tag']))
{
$tag = htmlspecialchars($attributes['tag']);
}
else
{
$tag = 'span';
}
unset($attributes['tag']);
$unhandledAttrs = $this->processUnhandledAttributes($attributes);
return "<{$tag} class=\"userTitle{$class}\" dir=\"auto\"{$unhandledAttrs}>{$userTitle}</{$tag}>";
}
return $main_reply;
}
For some reason, in some cases the above is not working as expected. It seems that there are cases that the code is not running.
I want to bypass any other addon / class extension and apply the correct titles ('A' or 'B'). It is for a small amount of accounts.
Any idea?