Xenforo option, return array

  • Thread starter Thread starter Deleted member 10469
  • Start date Start date
D

Deleted member 10469

Guest
Hello, I would like to know how to return an array of values ​​with options XenForo please.

Is there a basic code please?

Example:
1ftPV.jpg


Thank :)
 
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.
 
Hello, I have this:

1jh27


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 :

1jh36


I can not find what's wrong, I'm not accustomed to using the callback returns.
Can you help me please ? :)
 
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
            );
 
        }
 
    }
 
Back
Top Bottom