diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index 277d992f3a..cd7e8a382c 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -270,6 +270,12 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
$new_ary[$config_key] = '';
}
+ // For BC check if parameter is json format and if yes split $tpl_type in 2 parts only
+ if (isset($tpl_type[1]) && strpos($tpl_type[1], '{') !== false)
+ {
+ $tpl_type = explode(':', $vars['type'], 2);
+ }
+
switch ($tpl_type[0])
{
case 'password':
@@ -369,35 +375,37 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
break;
case 'radio':
- $tpl_type_cond = explode('_', $tpl_type[1]);
- $type_no = $tpl_type_cond[0] != 'disabled' && $tpl_type_cond[0] != 'enabled';
-
- $no_button = [
- 'type' => 'radio',
- 'name' => $name,
- 'value' => 0,
- 'checked' => !$new_ary[$config_key],
- 'label' => $type_no ? $language->lang('NO') : $language->lang('DISABLED'),
- ];
-
- $yes_button = [
- 'id' => $key,
- 'type' => 'radio',
- 'name' => $name,
- 'value' => 1,
- 'checked' => (bool) $new_ary[$config_key],
- 'label' => $type_no ? $language->lang('YES') : $language->lang('ENABLED'),
- ];
-
- $tpl = ['tag' => 'radio'];
- if ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled')
+ // Convert 'old' radio button parameters to json encoded string for BC
+ if (in_array($tpl_type[1], ['yes_no', 'enabled_disabled']))
{
- $tpl['buttons'] = [$yes_button, $no_button];
+ $params = explode('_', $tpl_type[1]);
+ $tpl_type[1] = '{"' . $params[0] . '":1, "' . $params[1] . '":0}';
}
- else
+
+ $params = json_decode($tpl_type[1], true);
+ $id_assigned = false;
+ $buttons = [];
+ foreach ($params as $param => $value)
{
- $tpl['buttons'] = [$no_button, $yes_button];
- }
+ $buttons[] = [
+ 'type' => 'radio',
+ 'name' => $name,
+ 'value' => $value,
+ 'checked' => $new_ary[$config_key] == $value,
+ 'label' => $language->lang(strtoupper($param)),
+ ];
+
+ // Only assign id to the one (1st) button in the list
+ if (!$id_assigned)
+ {
+ $buttons[key($buttons)]['id'] = $key;
+ }
+ };
+
+ $tpl = [
+ 'tag' => 'radio',
+ 'buttons' => $buttons,
+ ];
break;
case 'button':
diff --git a/phpBB/phpbb/template/twig/extension/forms.php b/phpBB/phpbb/template/twig/extension/forms.php
index ee47e19449..72be295e22 100644
--- a/phpBB/phpbb/template/twig/extension/forms.php
+++ b/phpBB/phpbb/template/twig/extension/forms.php
@@ -151,10 +151,7 @@ class forms extends AbstractExtension
try
{
return $environment->render('macros/forms/radio_buttons.twig', [
- 'FIRST_BUTTON' => $form_data['buttons'][0],
- 'FIRST_BUTTON_LABEL' => $form_data['buttons'][0]['label'],
- 'SECOND_BUTTON' => $form_data['buttons'][1],
- 'SECOND_BUTTON_LABEL' => $form_data['buttons'][1]['label'],
+ 'BUTTONS' => $form_data['buttons'],
]);
}
catch (\Twig\Error\Error $e)
diff --git a/phpBB/styles/all/template/macros/forms/radio_buttons.twig b/phpBB/styles/all/template/macros/forms/radio_buttons.twig
index 1ef7804c29..922eb1b432 100644
--- a/phpBB/styles/all/template/macros/forms/radio_buttons.twig
+++ b/phpBB/styles/all/template/macros/forms/radio_buttons.twig
@@ -1,2 +1,3 @@
-
-
+{% for button in BUTTONS %}
+
+{% endfor %}
diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php
index 67dc35ae73..6894f5d644 100644
--- a/tests/functional/extension_module_test.php
+++ b/tests/functional/extension_module_test.php
@@ -101,6 +101,16 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case
$this->assertStringContainsString('SETTING_9', $crawler->filter('dl')->eq(9)->filter('dt > label[for="setting_9"]')->text());
$this->assertStringContainsString('SETTING_9_EXPLAIN', $crawler->filter('dl')->eq(9)->filter('dt > span')->text());
$this->assertEquals(2, $crawler->filter('dl')->eq(9)->filter('dd > label > input[type="radio"]')->count());
+
+ $this->assertStringContainsString('SETTING_10', $crawler->filter('dl')->eq(10)->filter('dt > label[for="setting_10"]')->text());
+ $this->assertStringContainsString('SETTING_10_EXPLAIN', $crawler->filter('dl')->eq(10)->filter('dt > span')->text());
+ $this->assertEquals(3, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->count());
+ $this->assertEquals(1, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value'));
+ $this->assertStringContainsString('LABEL_1', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(0)->text());
+ $this->assertEquals(3, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value'));
+ $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());
}
public function test_ucp()
diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php
index 660d7eb1c9..77174c95f6 100644
--- a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php
+++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php
@@ -49,6 +49,7 @@ class main_module
'setting_7' => ['lang' => 'SETTING_7', 'validate' => 'email', 'type' => 'email:0:100', 'explain' => true],
'setting_8' => ['lang' => 'SETTING_8', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true],
'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true],
+ 'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'bool', 'type' => 'radio:{"LABEL_1":1, "LABEL_3":3, "LABEL_2":2}', 'explain' => true],
]
];