XF 2.1 New option for a new widget

SneakyDave

Well-known member
OK, I created a new widget based on the online users widget, and it works pretty well. I want to add an option to it to make the widget more useful, so I created/updated the admin template for the widget to include a new textarea that I want to make an option.

I now have the textarea for the widget displaying on the widget definition page, but nothing is being saved to it. I have the new option added to my widget class that extends AbstractWidget and a verifyOptions method.

Do I need a code event listener to save this option value, or what am I missing here? I could create an option group for the addon, but that seems a little clunky to have some options in the widget definition, and some in the site options.
 

TickTackk

Well-known member
Have you extended verifyOptions()? If not then you'll have to extend it to make the options actually save.
 

SneakyDave

Well-known member
Yeah, I extended the AbstractWidget Class, I know the widget is working the way I want it to.

I have a render method that works, and a verifyOptions method. It uses the same values as the online users widget, plus my new userArray textarea option. I've verified that this method is getting called...
PHP:
public function verifyOptions(\XF\Http\Request $request, array &$options, &$error = null)
{
    $options = $request->filter([
        'limit' => 'uint',
        'staffOnline' => 'bool',
        'staffQuery' => 'bool',
        'userArray' => 'str'
    ]);
    return true;
}

Is that all I need? Maybe str isn't valid for a textarea?
 

SneakyDave

Well-known member
Oh, that's where the problem is, lol. I don't include the value of the textarea!

I have this:
PHP:
<xf:textarearow name="options[userArray]" rows="7" autosize="true"
label="{{ phrase('user_array_list') }}" required="required" hint="{{ phrase('required') }}" />

But it should be something like this, adding the value....
PHP:
<xf:textarearow name="options[userArray]" value="{$options.userArray}" rows="7" autosize="true"
label="{{ phrase('user_array_list') }}" required="required" hint="{{ phrase('required') }}" />

Thanks for leading me to the right place Batpool52
 

TickTackk

Well-known member
Any particular reason behind using
PHP:
<xf:textarearow name="options[userArray]" rows="7" autosize="true"
label="{{ phrase('user_array_list') }}" required="required" hint="{{ phrase('required') }}">
$options.userArray
</xf:textarearow>
instead of
PHP:
<xf:textarearow name="options[userArray]" rows="7" autosize="true" label="{{ phrase('user_array_list') }}" required="required" hint="{{ phrase('required') }}" value="{$options.userArray}" />
 

SneakyDave

Well-known member
yeah, I couldn't remember how to apply the value, my original way wouldn't work. Edited my post to include the value tag in the element. Thanks.

Problem arose when I copied the textarea from the contact form template, which would never have a value assigned to it.
 
Top