XF 2.1 Widget Display Conditions

Ozzy47

Well-known member
So I have this in my setup file:

PHP:
<?php

namespace OzzModz\StaffWidget;

use XF\AddOn\AbstractSetup;

class Setup extends AbstractSetup
{
    public function install(array $stepParams = [])
    {
        $this->createWidget(

            'OzzModzStaff',
            'OzzModzStaff',
            [
                'positions' => [
                    'forum_list_sidebar' => 10
                ]
            ]

        );
    }

    public function upgrade(array $stepParams = [])
    {
        // TODO: Implement upgrade() method.
    }

    public function uninstall(array $stepParams = [])
    {
        $this->deleteWidget('OzzModzStaff');
    }
}

Now while it works great, I also need to add a display conditions to the widget, $xf.visitor.is_admin OR $xf.visitor.is_moderator How do I do that? This is my first time messing with a widget.
 
Ideally, conditional requirements should be defined in the actual widget handler (or template), rather than setting them in the widget, as an administrator could remove it - and this may leak private information, depending on the content of the widget.
 
Ideally, conditional requirements should be defined in the actual widget handler (or template), rather than setting them in the widget, as an administrator could remove it - and this may leak private information, depending on the content of the widget.

True, there is code there for that in the template, but I don't want the hassle of answering questions to why everyone sees a empty staff widget. ;)
 
Seems like wrapping the entire contents of the widget template in a conditional <xf:if is="$xf.visitor.is_admin OR $xf.visitor.is_moderator"> does hide it and its position as wanted. I would still like to add it during widget creation as well though.
 
Indeed. Otherwise you're just adding unneeded additional complexity @ozzy47.

To actually answer your question though, you'd have to find it and edit it post-install, or manually create it without using the provided methods.
 
Top Bottom