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

Validation Callback Signature

Discussion in 'XenForo Development Discussions' started by vbresults, Oct 14, 2011.

  1. vbresults

    vbresults Well-Known Member

    What is the validation callback signature for admin options?

    Thank you. :)
     
  2. James

    James Well-Known Member

    What do you mean by admin options? admin.php?options/?
     
  3. vbresults

    vbresults Well-Known Member

    Attached a screenshot; I know what class and method name I am using for the callback, I just don't know the method signature.
     

    Attached Files:

  4. borbole

    borbole Well-Known Member

    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.
     
  5. vbresults

    vbresults Well-Known Member

    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($dataXenForo_Arbitrary_Class $option, array $moreArbitraryVariables)
     
  6. James

    James Well-Known Member

    You validate it yourself with your own method.
     
  7. ragtek

    ragtek Guest

    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 &$valuesXenForo_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 &$wordsXenForo_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;
    }
     
  8. vbresults

    vbresults Well-Known Member

    Thank you! :)
     

Share This Page