1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[ticket/17100] Reuse form_macros in ACP and fix tests

PHPBB3-17100
This commit is contained in:
Marc Alexander
2023-01-30 16:48:18 +01:00
parent 015472ab91
commit 6473167d6e
12 changed files with 135 additions and 121 deletions

View File

@@ -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');

View File

@@ -37,7 +37,7 @@
<!-- IF S_ATTACHMENT_SETTINGS -->
{% import "form_macros.twig" as form_macros %}
{% import 'macros/form_macros.twig' as form_macros %}
<form id="attachsettings" method="post" action="{U_ACTION}">
<!-- BEGIN options -->
<!-- IF options.S_LEGEND -->
@@ -210,7 +210,7 @@
<dt><label for="extgroup_filesize">{L_MAX_EXTGROUP_FILESIZE}{L_COLON}</label></dt>
<dd>
<input type="number" id="extgroup_filesize" min="0" max="999999999999999" step="any" name="max_filesize" value="{EXTGROUP_FILESIZE}" />
{% from 'form_macros.twig' import select %}
{% from 'macros/form_macros.twig' import select %}
{{ select(EXT_GROUP_SIZE_OPTIONS) }}
</dd>
</dl>

View File

@@ -13,7 +13,7 @@
</div>
<!-- ENDIF -->
{% import "form_macros.twig" as form_macros %}
{% import 'macros/form_macros.twig' as form_macros %}
<form id="acp_board" method="post" action="{U_ACTION}">
<!-- BEGIN options -->

View File

@@ -32,7 +32,7 @@
<dl>
<dt><label for="{{ LANG_OPTIONS.id }}">{L_BOT_LANG}{L_COLON}</label><br /><span>{L_BOT_LANG_EXPLAIN}</span></dt>
<dd>
{% import "form_macros.twig" as form_macros %}
{% import 'macros/form_macros.twig' as form_macros %}
{{ form_macros.select(LANG_OPTIONS) }}
</dd>
</dl>

View File

@@ -65,7 +65,7 @@
<!-- ENDIF -->
<fieldset class="quick">
{% from 'form_macros.twig' import select %}
{% from 'macros/form_macros.twig' import select %}
{{ select(INACTIVE_OPTIONS) }}
<input class="button2" type="submit" name="submit" value="{L_SUBMIT}" />
<p class="small"><a href="#" onclick="marklist('inactive', 'mark', true); return false;">{L_MARK_ALL}</a> &bull; <a href="#" onclick="marklist('inactive', 'mark', false); return false;">{L_UNMARK_ALL}</a></p>

View File

@@ -43,7 +43,7 @@
<dl>
<dt><label for="{{ LANG_OPTIONS.id }}">{L_BOARD_LANGUAGE}{L_COLON}</label></dt>
<dd>
{% import "form_macros.twig" as form_macros %}
{% import 'macros/form_macros.twig' as form_macros %}
{{ form_macros.select(LANG_OPTIONS) }}
</dd>
</dl>

View File

@@ -1,85 +0,0 @@
{% macro input(form_data) %}
{% apply replace({"\n": ' ', '\t': ''}) %}
<input
{% if form_data.id %}id="{{ form_data.id }}"{% endif %}
type="{{ form_data.type }}"
name="{{ form_data.name }}"
{% if form_data.size %}size="{{ form_data.size }}"{% endif %}
{% if form_data.maxlength %}maxlength="{{ form_data.maxlength }}"{% endif %}
{% if form_data.min %}min="{{ form_data.min }}"{% endif %}
{% if form_data.max %}max="{{ form_data.max }}"{% endif %}
{% if form_data.step %}step="{{ form_data.step }}"{% endif %}
{% if form_data.type == 'password' %}autocomplete="off"{% endif %}
{% if form_data.checked %}checked="checked"{% endif %}
{% if form_data.class %}class="{{ form_data.class }}"{% endif %}
value="{{ form_data.value }}">
{% 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': ''}) %}
<textarea
id="{{ form_data.id }}"
name="{{ form_data.name }}"
rows="{{ form_data.rows }}"
cols="{{ form_data.cols }}">
{{ form_data.content }}
</textarea>
{% endapply %}
{% endmacro %}
{% macro radio_buttons(form_data) %}
<label>{{ _self.input(form_data.buttons[0]) ~ form_data.buttons[0].label }}</label>
<label>{{ _self.input(form_data.buttons[1]) ~ form_data.buttons[1].label }}</label>
{% endmacro %}
{% macro select(form_data, class, id, name, group_only) %}
{% apply replace({"\n": ' ', '\t': ''}) %}
<select
{% 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 %}>
{% endapply %}
{% for element in form_data.options %}
{% if not group_only and element.options %}
{% apply replace({"\n": ' ', '\t': ''}) %}
<optgroup
label="{{ element.label }}"
{% for key, value in element.data %}
data-{{ key }}="{{ value }}"
{% endfor %}>
{% endapply %}
{% for option in element.options %}
<option value="{{ option.value }}"{% if option.selected %} selected="selected"{% endif %}>{{ option.label }}</option>
{% endfor %}
</optgroup>
{% else %}
<option value="{{ element.value }}"{% if element.selected %} selected="selected"{% endif %}>{{ element.label }}</option>
{% endif %}
{% endfor %}
</select>
{% 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 %}

View File

@@ -1,5 +1,5 @@
<dl>
{% from "form_macros.twig" import select %}
{% from "macros/form_macros.twig" import select %}
<dt><label for="timezone">{{ lang('BOARD_TIMEZONE') | lang('COLON') }}</label></dt>
{% if TIMEZONE_OPTIONS %}
<dd id="tz_select_date hidden">

View File

@@ -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 = '<select id="' . $key . '" name="' . $name . '"' . (($size > 1) ? ' size="' . $size . '"' : '') . $data_toggle . '>' . $return . '</select>';
@@ -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

View File

@@ -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 %}