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

Xenforo option, return array

Zephyr

Well-known member
#1
Hello, I would like to know how to return an array of values ​​with options XenForo please.

Is there a basic code please?

Example:


Thank :)
 

Jeremy P

Well-known member
#2
You want to take a comma separated list from options and split the values into an array?

PHP:
$options = XenForo_Application::get('options');
 
$option = $options->yourOptionId; // this will get the value of your option, something like 1,10,27
$option = explode(',', $option);
 
// $option would now be: array('1', '10', '27');
You could also set the option itself to be an array instead of a string by default, but I would imagine that would require an validation callback to take the input and put it into an array.
 

Zephyr

Well-known member
#4
Hello, I have this:



Code :

Code:
<?php
 
abstract class XenCrea_ColorPicker_Option_ArrayDeClassEtId
{
    public static function ColorList($preparedOption, $canEdit)
    {
        $value = $preparedOption['option_value'];
 
        $options = XenForo_Application::get('ffff');
 
        $option = $options->yourOptionId; // this will get the value of your option, something like 1,10,27
        $option = explode(',', $option);
       
        // $option would now be: array('1', '10', '27');
       
        return $option;
    }
}
I have an error :



I can not find what's wrong, I'm not accustomed to using the callback returns.
Can you help me please ? :)
 

Lawrence

Well-known member
#5
If I understand what you want to do, you have to set the Edit Format to PHP Callback.
In the Format Parameters place your callback there: XenCrea_ColorPicker_Option_ArrayDeClassEtId::renderColorList (I changed the name of the function to reflect what it will do)

Your Format Parameters callback will take care of rendering the options and should look something like this:

PHP:
    class XenCrea_ColorPicker_Option_ArrayDeClassEtId
    {
 
        public static function renderColorList(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
        {
 
            $preparedOption['formatParams'] = XenForo_Model::create('XenCrea_ColorPicker_Model_ColorOptions')->getColors(
            $preparedOption['option_value']
            );
 
            return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal(
            'option_list_option_textbox',
            $view, $fieldPrefix, $preparedOption, $canEdit
            );
 
        }
 
    }