diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index 3f0aa4009b..68f8ee634a 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -53,12 +53,19 @@ $module_id = $request->variable('i', ''); $mode = $request->variable('mode', ''); // Set custom style for admin area -$template->set_custom_style(array( - array( - 'name' => 'adm', - 'ext_path' => 'adm/style/', - ), -), $phpbb_admin_path . 'style'); +/** @var \phpbb\template\base $template */ +$template->set_custom_style( + [ + [ + 'name' => 'adm', + 'ext_path' => 'adm/style/', + ] + ], + [ + $phpbb_admin_path . 'style', + $phpbb_root_path . 'styles/all/template/', + ], +); $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style'); diff --git a/phpBB/adm/style/acp_attachments.html b/phpBB/adm/style/acp_attachments.html index 6448c51c80..38be1baac0 100644 --- a/phpBB/adm/style/acp_attachments.html +++ b/phpBB/adm/style/acp_attachments.html @@ -37,7 +37,7 @@ - {% import "form_macros.twig" as form_macros %} + {% import 'macros/form_macros.twig' as form_macros %}
@@ -210,7 +210,7 @@
- {% from 'form_macros.twig' import select %} + {% from 'macros/form_macros.twig' import select %} {{ select(EXT_GROUP_SIZE_OPTIONS) }}
diff --git a/phpBB/adm/style/acp_board.html b/phpBB/adm/style/acp_board.html index 8d539de10c..b809e2dfef 100644 --- a/phpBB/adm/style/acp_board.html +++ b/phpBB/adm/style/acp_board.html @@ -13,7 +13,7 @@ -{% import "form_macros.twig" as form_macros %} +{% import 'macros/form_macros.twig' as form_macros %} diff --git a/phpBB/adm/style/acp_bots.html b/phpBB/adm/style/acp_bots.html index 94103e0ec9..2b9fec668f 100644 --- a/phpBB/adm/style/acp_bots.html +++ b/phpBB/adm/style/acp_bots.html @@ -32,7 +32,7 @@

{L_BOT_LANG_EXPLAIN}
- {% import "form_macros.twig" as form_macros %} + {% import 'macros/form_macros.twig' as form_macros %} {{ form_macros.select(LANG_OPTIONS) }}
diff --git a/phpBB/adm/style/acp_inactive.html b/phpBB/adm/style/acp_inactive.html index 19a766fd8c..81c019c47c 100644 --- a/phpBB/adm/style/acp_inactive.html +++ b/phpBB/adm/style/acp_inactive.html @@ -65,7 +65,7 @@
- {% from 'form_macros.twig' import select %} + {% from 'macros/form_macros.twig' import select %} {{ select(INACTIVE_OPTIONS) }}

{L_MARK_ALL}{L_UNMARK_ALL}

diff --git a/phpBB/adm/style/acp_users_prefs.html b/phpBB/adm/style/acp_users_prefs.html index 0cf21e19a6..11f6a71e20 100644 --- a/phpBB/adm/style/acp_users_prefs.html +++ b/phpBB/adm/style/acp_users_prefs.html @@ -43,7 +43,7 @@
- {% import "form_macros.twig" as form_macros %} + {% import 'macros/form_macros.twig' as form_macros %} {{ form_macros.select(LANG_OPTIONS) }}
diff --git a/phpBB/adm/style/form_macros.twig b/phpBB/adm/style/form_macros.twig deleted file mode 100644 index 35fe1bf4df..0000000000 --- a/phpBB/adm/style/form_macros.twig +++ /dev/null @@ -1,85 +0,0 @@ -{% macro input(form_data) %} - {% apply replace({"\n": ' ', '\t': ''}) %} - - {% endapply %} -{% endmacro %} - -{% macro dimension(form_data) %} - {{ _self.input(form_data.width) }} x {{ _self.input(form_data.height) }} -{% endmacro %} - -{% macro textarea(form_data) %} - {% apply replace({"\n": ' ', '\t': ''}) %} - - {% endapply %} -{% endmacro %} - -{% macro radio_buttons(form_data) %} - - -{% endmacro %} - -{% macro select(form_data, class, id, name, group_only) %} - {% apply replace({"\n": ' ', '\t': ''}) %} - -{% endmacro %} - -{% macro build_template(form_data) %} - {% if form_data.tag == 'input' %} - {{ _self.input(form_data) }} - {% elseif form_data.tag == 'dimension' %} - {{ _self.dimension(form_data) }} - {% elseif form_data.tag == 'radio' %} - {{ _self.radio_buttons(form_data) }} - {% elseif form_data.tag == 'select' %} - {{ _self.select(form_data) }} - {% elseif form_data.tag == 'textarea' %} - {{ _self.textarea(form_data) }} - {% elseif form_data[0] %} - {% for element in form_data %} - {{ _self.build_template(element) }} - {% endfor %} - {% endif %} - {% if form_data.append %}{{ form_data.append }}{% endif %} -{% endmacro %} diff --git a/phpBB/adm/style/timezone_option.html b/phpBB/adm/style/timezone_option.html index 7ca0e3be26..58b88cf6b4 100644 --- a/phpBB/adm/style/timezone_option.html +++ b/phpBB/adm/style/timezone_option.html @@ -1,5 +1,5 @@
- {% from "form_macros.twig" import select %} + {% from "macros/form_macros.twig" import select %}
{% if TIMEZONE_OPTIONS %}
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 716d9f6d53..007582c6f8 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -485,9 +485,10 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars) if ($tpl_type[0] == 'select') { + $size = (isset($tpl_type[1])) ? (int)$tpl_type[1] : 1; + if (is_string($return)) { - $size = (isset($tpl_type[1])) ? (int)$tpl_type[1] : 1; $data_toggle = (!empty($tpl_type[2])) ? ' data-togglable-settings="true"' : ''; $tpl = ''; @@ -501,6 +502,12 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars) 'toggleable' => !empty($tpl_type[2]), 'options' => $return, ]; + + // Add size if it differs from default value of 1 + if ($size != 1) + { + $tpl['size'] = $size; + } } } else diff --git a/phpBB/styles/all/template/macros/form_macros.twig b/phpBB/styles/all/template/macros/form_macros.twig index 074891a5ee..a4fa779ff8 100644 --- a/phpBB/styles/all/template/macros/form_macros.twig +++ b/phpBB/styles/all/template/macros/form_macros.twig @@ -43,7 +43,8 @@ {% if id %}id="{{ id }}"{% endif %} {% if class %}class="{{ class }}"{% endif %} name="{% if name %}{{ name }}{% else %}{{ form_data.name }}{% endif %}" - {% if form_data.toggleable %}data-togglable-settings="true"{% endif %}> + {% if form_data.toggleable %}data-togglable-settings="true"{% endif %} + {% if form_data.size %}size="{{ form_data.size }}"{% endif %}> {% endapply %} {% for element in form_data.options %} {% if not group_only and element.options %} diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 9d3b244bc0..76558152ff 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -74,11 +74,12 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case */ public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected) { - global $user, $phpbb_dispatcher; + global $user, $phpbb_dispatcher, $language; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); + $language = new phpbb_mock_lang(); + $user->lang = $language; $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } @@ -421,24 +422,69 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case public function build_cfg_template_select_data() { - return array( - array( - array('select'), + return [ + [ + ['select'], 'key_name', - array('config_key_name' => '0'), + ['config_key_name' => '0'], 'config_key_name', - array('method' => 'select_helper'), - '', - ), - array( - array('select', 8), + ['method' => 'select_helper'], + [ + 'tag' => 'select', + 'id' => 'key_name', + 'name' => 'config[config_key_name]', + 'options' => [ + [ + 'value' => 1, + 'label' => 'First_Option', + 'selected' => false, + ], + [ + 'value' => 2, + 'label' => 'Second_Option', + 'selected' => true, + ], + [ + 'value' => 3, + 'label' => 'Third_Option', + 'selected' => false, + ] + ], + 'toggleable' => false, + ], + ], + [ + ['select', 8], 'key_name', - array('config_key_name' => '1'), + ['config_key_name' => '1'], 'config_key_name', - array('method' => 'select_helper'), - '', - ), - ); + ['method' => 'select_helper'], + [ + 'tag' => 'select', + 'id' => 'key_name', + 'name' => 'config[config_key_name]', + 'size' => 8, + 'options' => [ + [ + 'value' => 1, + 'label' => 'First_Option', + 'selected' => false, + ], + [ + 'value' => 2, + 'label' => 'Second_Option', + 'selected' => true, + ], + [ + 'value' => 3, + 'label' => 'Third_Option', + 'selected' => false, + ] + ], + 'toggleable' => false, + ], + ], + ]; } /** @@ -446,11 +492,12 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case */ public function test_build_cfg_template_select($tpl_type, $key, $new, $config_key, $vars, $expected) { - global $module, $user, $phpbb_dispatcher; + global $module, $user, $phpbb_dispatcher, $language; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); + $language = new phpbb_mock_lang(); + $user->lang = $language; $user->module = $this; $module = $user; diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php index ed90454c9f..e59f25e977 100644 --- a/tests/functions_acp/build_select_test.php +++ b/tests/functions_acp/build_select_test.php @@ -34,7 +34,18 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case 'second' => 'SEC_OPTION', ), false, - '', + [ + [ + 'value' => 'test', + 'label' => 'TEST', + 'selected' => false, + ], + [ + 'value' => 'second', + 'label' => 'SEC_OPTION', + 'selected' => false, + ], + ], ), array( array( @@ -42,7 +53,18 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case 'second' => 'SEC_OPTION', ), 'test', - '', + [ + [ + 'value' => 'test', + 'label' => 'TEST', + 'selected' => true, + ], + [ + 'value' => 'second', + 'label' => 'SEC_OPTION', + 'selected' => false, + ], + ], ), array( array( @@ -50,7 +72,18 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case 'second' => 'SEC_OPTION', ), 'second', - '', + [ + [ + 'value' => 'test', + 'label' => 'TEST', + 'selected' => false, + ], + [ + 'value' => 'second', + 'label' => 'SEC_OPTION', + 'selected' => true, + ], + ], ), ); } @@ -60,6 +93,10 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case */ public function test_build_select($option_ary, $option_default, $expected) { + global $language; + + $language = new phpbb_mock_lang(); + $this->assertEquals($expected, build_select($option_ary, $option_default)); } }