• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Validation Callback Signature

borbole

Well-known member
#4
Attached a screenshot; I know what class and method name I am using for the callback, I just don't know the method signature.
For some reason I am not able to view the screenshot that you have attched, but I assume that you mean at the options when you are creating an option for your mod and not when creating the a Code Event Listeners. In that case you can leave that empty.
 

vbresults

Well-known member
#5
Yes, I am talking about the two fields at the options add/edit page, but no, I don't want to leave it empty; I want to validate the data with a callback. I am asking what the signature for the validation callback method is since I don't see it anywhere. Looking for something like...

PHP:
function validateOption($data, XenForo_Arbitrary_Class $option, array $moreArbitraryVariables)
 
R

ragtek

Guest
#7
Just check the existing code;)

e.g. => this option is using a validation class
Code:
<option option_id="autoEmbedMedia" edit_format="template" data_type="array" can_backup="1" validation_class="XenForo_Option_AutoEmbedMedia" validation_method="verifyOption">
    <default_value>a:2:{s:9:"embedType";s:1:"1";s:10:"linkBbCode";s:28:"[i][size=2]{$url}[/size][/i]";}</default_value>
    <edit_format_params>option_template_autoEmbedMedia</edit_format_params>
    <sub_options>embedType
linkBbCode</sub_options>
    <relation group_id="messageOptions" display_order="120"/>
  </option>
PHP:
    public static function verifyOption(array &$values, XenForo_DataWriter $dw, $fieldName)
    {
        if (empty($values['linkBbCode']))
        {
            $values['linkBbCode'] = '[i][size=2]{$url}[/size][/i]';
        }

        if ($values['embedType'] != XenForo_Helper_Media::AUTO_EMBED_MEDIA_DISABLED)
        {
            if (strpos($values['linkBbCode'], '{$url}') === false)
            {
                $dw->error(new XenForo_Phrase('link_bbcode_must_include_url_token'), $fieldName);
                return false;
            }
        }

        return true;
    }
or
Code:
<option option_id="censorWords" edit_format="callback" data_type="array" can_backup="1" validation_class="XenForo_Option_CensorWords" validation_method="verifyOption">
    <default_value>a:0:{}</default_value>
    <edit_format_params>XenForo_Option_CensorWords::renderOption</edit_format_params>
    <sub_options>*</sub_options>
    <relation group_id="censoringOptions" display_order="110"/>
  </option>
PHP:
abstract class XenForo_Option_CensorWords
{

public static function verifyOption(array &$words, XenForo_DataWriter $dw, $fieldName)
{
$output = array(
'exact' => array(),
'any' => array()
);

foreach ($words AS $word)
{
if (!isset($word['word']) || strval($word['word']) === '')
{
continue;
}

$writePosition = (!empty($word['exact']) ? 'exact' : 'any');

if (isset($word['replace']) && strval($word['replace']) !== '')
{
$output[$writePosition][strval($word['word'])] = strval($word['replace']);
}
else
{
$output[$writePosition][strval($word['word'])] = utf8_strlen($word['word']);
}
}

if (!$output['exact'])
{
unset($output['exact']);
}
if (!$output['any'])
{
unset($output['any']);
}

$words = $output;

return true;
}