mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17151] Reimplement radio buttons yes_no / enabled_disabled shorthands
PHPBB3-17151
This commit is contained in:
parent
2d0969e3e1
commit
6349d3c126
3 changed files with 47 additions and 29 deletions
|
@ -374,47 +374,48 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
|
|||
break;
|
||||
|
||||
case 'radio':
|
||||
if (!isset($vars['method']) && !isset($vars['function']))
|
||||
{
|
||||
if (in_array($tpl_type[1], ['yes_no', 'enabled_disabled']))
|
||||
{
|
||||
$options = array_reverse(explode('_', strtoupper($tpl_type[1])));
|
||||
krsort($options);
|
||||
$tpl_type = array_merge ($tpl_type, build_radio($new_ary[$config_key], $config_key, $options));
|
||||
}
|
||||
}
|
||||
case 'button':
|
||||
case 'select':
|
||||
case 'custom':
|
||||
if (isset($vars['method']))
|
||||
{
|
||||
$call = array($module->module, $vars['method']);
|
||||
}
|
||||
else if (isset($vars['function']))
|
||||
{
|
||||
$call = $vars['function'];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
$args = [];
|
||||
$call = $vars['function'] ?? (isset($vars['method']) ? [$module->module, $vars['method']] : false);
|
||||
|
||||
if (isset($vars['params']))
|
||||
if ($call)
|
||||
{
|
||||
$args = array();
|
||||
foreach ($vars['params'] as $value)
|
||||
if (isset($vars['params']))
|
||||
{
|
||||
switch ($value)
|
||||
foreach ($vars['params'] as $value)
|
||||
{
|
||||
case '{CONFIG_VALUE}':
|
||||
$value = $new_ary[$config_key];
|
||||
break;
|
||||
switch ($value)
|
||||
{
|
||||
case '{CONFIG_VALUE}':
|
||||
$value = $new_ary[$config_key];
|
||||
break;
|
||||
|
||||
case '{KEY}':
|
||||
$value = $config_key;
|
||||
break;
|
||||
case '{KEY}':
|
||||
$value = $config_key;
|
||||
break;
|
||||
}
|
||||
|
||||
$args[] = $value;
|
||||
}
|
||||
|
||||
$args[] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$args = array($new_ary[$config_key], $config_key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$args = array($new_ary[$config_key], $config_key);
|
||||
}
|
||||
|
||||
$return = call_user_func_array($call, $args);
|
||||
$return = $call ? call_user_func_array($call, $args) : [];
|
||||
|
||||
if (in_array($tpl_type[0], ['select', 'radio', 'button']))
|
||||
{
|
||||
|
|
|
@ -54,6 +54,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case
|
|||
|
||||
public function test_acp()
|
||||
{
|
||||
$this->add_lang('common');
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
|
@ -111,6 +112,20 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case
|
|||
$this->assertStringContainsString('LABEL_3', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(1)->text());
|
||||
$this->assertEquals(2, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(2)->attr('value'));
|
||||
$this->assertStringContainsString('LABEL_2', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(2)->text());
|
||||
|
||||
$this->assertStringContainsString('SETTING_11', $crawler->filter('dl')->eq(11)->filter('dt > label[for="setting_11"]')->text());
|
||||
$this->assertStringContainsString('SETTING_11_EXPLAIN', $crawler->filter('dl')->eq(11)->filter('dt > span')->text());
|
||||
$this->assertEquals('1', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value'));
|
||||
$this->assertEquals('0', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value'));
|
||||
$this->assertContainsLang('YES', $crawler->filter('dl')->eq(11)->filter('dd > label')->eq(0)->text());
|
||||
$this->assertContainsLang('NO', $crawler->filter('dl')->eq(11)->filter('dd > label')->eq(1)->text());
|
||||
|
||||
$this->assertStringContainsString('SETTING_12', $crawler->filter('dl')->eq(12)->filter('dt > label[for="setting_12"]')->text());
|
||||
$this->assertStringContainsString('SETTING_12_EXPLAIN', $crawler->filter('dl')->eq(12)->filter('dt > span')->text());
|
||||
$this->assertContainsLang('ENABLED', $crawler->filter('dl')->eq(12)->filter('dd > label')->eq(0)->text());
|
||||
$this->assertEquals(1, $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value'));
|
||||
$this->assertContainsLang('DISABLED', $crawler->filter('dl')->eq(12)->filter('dd > label')->eq(1)->text());
|
||||
$this->assertEquals(0, $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value'));
|
||||
}
|
||||
|
||||
public function test_ucp()
|
||||
|
|
|
@ -50,6 +50,8 @@ class main_module
|
|||
'setting_8' => ['lang' => 'SETTING_8', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true],
|
||||
'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']], 'explain' => true],
|
||||
'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'LABEL_1', 3 => 'LABEL_3', 2 => 'LABEL_2']], 'explain' => true],
|
||||
'setting_11'=> ['lang' => 'SETTING_11', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
|
||||
'setting_12'=> ['lang' => 'SETTING_12', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true],
|
||||
]
|
||||
];
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue