mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/17151] Deduplicate code for building configuration options data
PHPBB3-17151
This commit is contained in:
parent
7b04e411b6
commit
7f365855ce
1 changed files with 46 additions and 88 deletions
|
@ -247,18 +247,19 @@ function h_radio($name, $input_ary, $input_default = false, $id = false, $key =
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML-less version of build_cfg_template
|
* Build configuration data arrays or templates for configuration settings
|
||||||
*
|
*
|
||||||
* @param array $tpl_type Template type
|
* @param array $tpl_type Configuration setting type data
|
||||||
* @param string $key Config key
|
* @param string $key Configuration option name
|
||||||
* @param $new_ary
|
* @param array $new_ary Updated configuration data
|
||||||
* @param $config_key
|
* @param string $config_key Configuration option name
|
||||||
* @param $vars
|
* @param Array $vars Configuration setting data
|
||||||
* @return array
|
*
|
||||||
|
* @return array|string
|
||||||
*/
|
*/
|
||||||
function phpbb_build_cfg_template(array $tpl_type, string $key, &$new_ary, $config_key, $vars): array
|
function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||||
{
|
{
|
||||||
global $language;
|
global $language, $module, $phpbb_dispatcher;
|
||||||
|
|
||||||
$tpl = [];
|
$tpl = [];
|
||||||
$name = 'config[' . $config_key . ']';
|
$name = 'config[' . $config_key . ']';
|
||||||
|
@ -399,78 +400,9 @@ function phpbb_build_cfg_template(array $tpl_type, string $key, &$new_ary, $conf
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'select':
|
|
||||||
$tpl = [
|
|
||||||
'tag' => 'select',
|
|
||||||
'class' => $tpl_type['class'] ?? false,
|
|
||||||
'id' => $key,
|
|
||||||
'data' => $tpl_type['data'] ?? [],
|
|
||||||
'name' => $name,
|
|
||||||
'toggleable' => !empty($tpl_type[2]) || !empty($tpl_type['toggleable']),
|
|
||||||
'options' => $tpl_type['options'],
|
|
||||||
'group_only' => $tpl_type['group_only'] ?? false,
|
|
||||||
'size' => $tpl_type[1] ?? $tpl_type['size'] ?? 1,
|
|
||||||
'multiple' => $tpl_type['multiple'] ?? false,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'button':
|
case 'button':
|
||||||
$tpl = [
|
|
||||||
'tag' => 'input',
|
|
||||||
'class' => $tpl_type['options']['class'],
|
|
||||||
'id' => $key,
|
|
||||||
'type' => $tpl_type['options']['type'],
|
|
||||||
'name' => $tpl_type['options']['name'] ?? $name,
|
|
||||||
'value' => $tpl_type['options']['value'],
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $tpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build configuration template for acp configuration pages
|
|
||||||
*/
|
|
||||||
function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
|
||||||
{
|
|
||||||
global $module, $phpbb_dispatcher;
|
|
||||||
|
|
||||||
$tpl = '';
|
|
||||||
$name = 'config[' . $config_key . ']';
|
|
||||||
|
|
||||||
// Make sure there is no notice printed out for non-existent config options (we simply set them)
|
|
||||||
if (!isset($new_ary[$config_key]))
|
|
||||||
{
|
|
||||||
$new_ary[$config_key] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($tpl_type[0])
|
|
||||||
{
|
|
||||||
case 'password':
|
|
||||||
case 'text':
|
|
||||||
case 'url':
|
|
||||||
case 'email':
|
|
||||||
case 'tel':
|
|
||||||
case 'search':
|
|
||||||
case 'color':
|
|
||||||
case 'datetime':
|
|
||||||
case 'datetime-local':
|
|
||||||
case 'month':
|
|
||||||
case 'week':
|
|
||||||
case 'date':
|
|
||||||
case 'time':
|
|
||||||
case 'number':
|
|
||||||
case 'range':
|
|
||||||
case 'dimension':
|
|
||||||
case 'textarea':
|
|
||||||
case 'radio':
|
|
||||||
$tpl = phpbb_build_cfg_template($tpl_type, $key, $new_ary, $config_key, $vars);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'select':
|
case 'select':
|
||||||
case 'custom':
|
case 'custom':
|
||||||
|
|
||||||
if (isset($vars['method']))
|
if (isset($vars['method']))
|
||||||
{
|
{
|
||||||
$call = array($module->module, $vars['method']);
|
$call = array($module->module, $vars['method']);
|
||||||
|
@ -513,7 +445,33 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||||
if (in_array($tpl_type[0], ['select', 'button']))
|
if (in_array($tpl_type[0], ['select', 'button']))
|
||||||
{
|
{
|
||||||
$tpl_type = array_merge($tpl_type, $return);
|
$tpl_type = array_merge($tpl_type, $return);
|
||||||
$tpl = phpbb_build_cfg_template($tpl_type, $key, $new_ary, $config_key, $vars);
|
|
||||||
|
if ($tpl_type[0] == 'select')
|
||||||
|
{
|
||||||
|
$tpl = [
|
||||||
|
'tag' => 'select',
|
||||||
|
'class' => $tpl_type['class'] ?? false,
|
||||||
|
'id' => $key,
|
||||||
|
'data' => $tpl_type['data'] ?? [],
|
||||||
|
'name' => $name,
|
||||||
|
'toggleable' => !empty($tpl_type[2]) || !empty($tpl_type['toggleable']),
|
||||||
|
'options' => $tpl_type['options'],
|
||||||
|
'group_only' => $tpl_type['group_only'] ?? false,
|
||||||
|
'size' => $tpl_type[1] ?? $tpl_type['size'] ?? 1,
|
||||||
|
'multiple' => $tpl_type['multiple'] ?? false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$tpl = [
|
||||||
|
'tag' => 'input',
|
||||||
|
'class' => $tpl_type['options']['class'],
|
||||||
|
'id' => $key,
|
||||||
|
'type' => $tpl_type['options']['type'],
|
||||||
|
'name' => $tpl_type['options']['name'] ?? $name,
|
||||||
|
'value' => $tpl_type['options']['value'],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -542,15 +500,15 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
||||||
* Overwrite the html code we display for the config value
|
* Overwrite the html code we display for the config value
|
||||||
*
|
*
|
||||||
* @event core.build_config_template
|
* @event core.build_config_template
|
||||||
* @var array tpl_type Config type array:
|
* @var array tpl_type Config type array:
|
||||||
* 0 => data type
|
* 0 => data type
|
||||||
* 1 [optional] => string: size, int: minimum
|
* 1 [optional] => string: size, int: minimum
|
||||||
* 2 [optional] => string: max. length, int: maximum
|
* 2 [optional] => string: max. length, int: maximum
|
||||||
* @var string key Should be used for the id attribute in html
|
* @var string key Should be used for the id attribute in html
|
||||||
* @var array new Array with the config values we display
|
* @var array new Array with the config values we display
|
||||||
* @var string name Should be used for the name attribute
|
* @var string name Should be used for the name attribute
|
||||||
* @var array vars Array with the options for the config
|
* @var array vars Array with the options for the config
|
||||||
* @var string tpl The resulting html code we display
|
* @var array|string tpl The resulting html code we display
|
||||||
* @since 3.1.0-a1
|
* @since 3.1.0-a1
|
||||||
*/
|
*/
|
||||||
$vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl');
|
$vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl');
|
||||||
|
|
Loading…
Add table
Reference in a new issue